From efc4ebd67444a34bc66ac04c23f2410fcdd47ef8 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期二, 26 八月 2025 18:19:29 +0800 Subject: [PATCH] 原料大小货位二楼输送线,堆垛机代码提交 --- 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs | 911 +++++++++++++++++++++----------------------------------- 1 files changed, 339 insertions(+), 572 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 8a041a3..1f7d0db 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" @@ -1,13 +1,16 @@ 锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; +using SqlSugar; using System; 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; using WIDESEA_Common.CommonEnum; using WIDESEA_Common.LocationEnum; +using WIDESEA_Common.MaterielEnum; using WIDESEA_Common.OrderEnum; using WIDESEA_Common.StockEnum; using WIDESEA_Common.TaskEnum; @@ -15,6 +18,7 @@ using WIDESEA_Core; using WIDESEA_Core.Helper; using WIDESEA_DTO; +using WIDESEA_DTO.Basic; using WIDESEA_DTO.Task; using WIDESEA_Model.Models; @@ -22,437 +26,6 @@ { public partial class TaskService { - /// <summary> - /// 鐢宠鍏ュ簱浠诲姟(PDA浣跨敤锛屼粎鎵樼洏缁戝畾鍏ュ簱绔欏彴锛屼笉鍒嗛厤璐т綅) - /// </summary> - /// <param name="saveModel"></param> - /// <returns></returns> - public WebResponseContent RequestInboundTask(SaveModel saveModel) - { - try - { - var palletCode = saveModel.MainData["barcode"].ToString(); - var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); - var stationCode = saveModel.MainData["startPoint"].ToString(); - Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId); - if (warehouse == null) - { - return WebResponseContent.Instance.Error($"鏈壘鍒板簱鍖�"); - } - - Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode && x.WarehouseId == warehouseId); - if (task != null) - { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟"); - } - - if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && warehouse.WarehouseCode != WarehouseEnum.HA60.ToString()) - { - return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�"); - } - - Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode== palletCode).Includes(x=>x.Details).First(); - if (stockInfo == null) - { - return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�"); - } - if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt()) - { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱"); - } - if (!string.IsNullOrEmpty(stockInfo.LocationCode)) - { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅"); - } - if (warehouseId != stockInfo.WarehouseId) - { - return WebResponseContent.Instance.Error($"浠撳簱涓嶆纭�"); - } - if (warehouse.WarehouseCode == WarehouseEnum.HA60.ToString()) - { - Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseId); - if (locationInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒板綋鍓嶅簱鍖鸿揣浣嶄俊鎭�"); - return DeviceRequestInboundTask(stationCode, locationInfo.RoadwayNo, palletCode); - } - else - { - Dt_Task newTask = new Dt_Task() - { - CurrentAddress = stationCode, - Grade = 0, - NextAddress = "", - PalletCode = palletCode, - Roadway = "", - SourceAddress = stationCode, - TargetAddress = "", - TaskType = TaskTypeEnum.Inbound.ObjToInt(), - TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = stockInfo.WarehouseId, - PalletType = stockInfo.PalletType, - MaterielCode = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode, - Quantity = (float)stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.StockQuantity, - }; - //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗� - Dt_InboundOrder? inboundOrder = null; - if (stockInfo!=null && stockInfo.Details.Count>0) - { - string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; - inboundOrder =_inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()); - if (inboundOrder!=null) - { - newTask.OrderNo = inboundOrder.InboundOrderNo; - } - } - - if (inboundOrder != null) - { - if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt(); - newTask.OrderNo = inboundOrder.InboundOrderNo; - } - else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt(); - newTask.OrderNo = inboundOrder.InboundOrderNo; - } - } - if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt()) - { - stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(); - } - else if (stockInfo.StockStatus == StockStatusEmun.鎷i�夊畬鎴�.ObjToInt()) - { - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - newTask.TaskType = TaskTypeEnum.InPick.ObjToInt(); - } - else - { - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - } - - if (warehouse.WarehouseCode==WarehouseEnum.HA57.ToString()) - { - Dt_Task dt_TaskMesReturn = BaseDal.QueryFirst(x=>x.TaskType==TaskTypeEnum.MesMatReturn.ObjToInt() && x.TaskStatus!=TaskStatusEnum.SC_Executing.ObjToInt()); - if (dt_TaskMesReturn!=null) - { - return WebResponseContent.Instance.Error($"閫�鏂欎换鍔℃鎵ц"); - } - } - _unitOfWorkManage.BeginTran(); - int taskId = BaseDal.AddData(newTask); - newTask.TaskId = taskId; - _stockRepository.StockInfoRepository.UpdateData(stockInfo); - _unitOfWorkManage.CommitTran(); - PushTasksToWCS(new List<Dt_Task> { newTask }); - return WebResponseContent.Instance.OK(data: newTask); - } - } - catch (Exception ex) - { - _unitOfWorkManage.RollbackTran(); - return WebResponseContent.Instance.Error(ex.Message); - } - } - - /// <summary> - /// 鍏ョ┖绠� - /// </summary> - /// <param name="barcode"></param> - /// <param name="address"></param> - /// <param name="WarehouseId"></param> - /// <returns></returns> - public WebResponseContent InEmpty(string barcode, string address, int WarehouseId) - { - try - { - Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId); - if (warehouse == null) - { - return WebResponseContent.Instance.Error($"鏈壘鍒板簱鍖�"); - } - Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode && x.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt()); - if (stockInfo != null) throw new Exception($"鎵樼洏鍙峰凡瀛樺湪"); - stockInfo = new Dt_StockInfo() - { - PalletCode = barcode, - StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(), - WarehouseId = WarehouseId, - PalletType = PalletTypeEnum.Empty.ObjToInt(), - Details = new List<Dt_StockInfoDetail>() - }; - Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == WarehouseId); - if (locationInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒板綋鍓嶅簱鍖鸿揣浣嶄俊鎭�"); - locationInfo = _basicService.LocationInfoService.AssignLocation(locationInfo.RoadwayNo, ((PalletTypeEnum)stockInfo.PalletType).ObjToInt(), stockInfo.WarehouseId); - if (locationInfo == null) - { - return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅"); - } - - Dt_Task newTask = new Dt_Task() - { - CurrentAddress = address, - Grade = 0, - NextAddress = locationInfo.LocationCode, - PalletCode = barcode, - Roadway = locationInfo.RoadwayNo, - SourceAddress = address, - TargetAddress = locationInfo.LocationCode, - TaskType = TaskTypeEnum.InEmpty.ObjToInt(), - TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = stockInfo.WarehouseId, - PalletType = stockInfo.PalletType - }; - locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); - _unitOfWorkManage.BeginTran(); - int taskId = BaseDal.AddData(newTask); - newTask.TaskId = taskId; - _basicRepository.LocationInfoRepository.UpdateData(locationInfo); - _stockRepository.StockInfoRepository.AddData(stockInfo); - _unitOfWorkManage.CommitTran(); - PushTasksToWCS(new List<Dt_Task> { newTask }); - PutFinish(address, newTask.PalletCode, newTask.TaskNum.ToString()); - return WebResponseContent.Instance.OK(); - } - catch (Exception ex) - { - _unitOfWorkManage.RollbackTran(); - return WebResponseContent.Instance.Error(ex.Message); - } - } - - /// <summary> - /// - /// </summary> - /// <param name="qty"></param> - /// <param name="address"></param> - /// <param name="WarehouseId"></param> - /// <param name="barcode"></param> - /// <returns></returns> - public WebResponseContent OutEmpty(int qty, string address, int WarehouseId, string barcode) - { - try - { - Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId); - if (warehouse == null) - { - return WebResponseContent.Instance.Error($"鏈壘鍒板簱鍖�"); - } - List<Dt_StockInfo> stockInfos = null; - if (string.IsNullOrEmpty(barcode)) - { - stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(), qty, nameof(Dt_StockInfo.CreateDate)); - } - else - { - stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.PalletCode == barcode); - if (stockInfos.Count == 0) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}鏈壘鍒扮┖绠便�恵barcode}銆�"); - } - - if (stockInfos.Count < qty) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}绌虹搴撳瓨涓嶈冻,搴撳瓨鏁般�恵stockInfos.Count}銆�"); - List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutEmpty); - stockInfos.ForEach(x => - { - x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt(); - }); - tasks.ForEach(x => - { - x.TargetAddress = address; - x.NextAddress = address; - }); - _unitOfWorkManage.BeginTran(); - BaseDal.AddData(tasks); - _stockRepository.StockInfoRepository.UpdateData(stockInfos); - _unitOfWorkManage.CommitTran(); - PushTasksToWCS(tasks); - return WebResponseContent.Instance.OK(); - } - catch (Exception ex) - { - return WebResponseContent.Instance.Error(ex.Message); - } - } - - /// <summary> - /// - /// </summary> - /// <param name="stationCode"></param> - /// <param name="roadwayNo"></param> - /// <param name="palletCode"></param> - /// <returns></returns> - public WebResponseContent DeviceRequestInboundTask(string stationCode, string roadwayNo, string palletCode,string materielBoxCode = "") - { - try - { - Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode); - if (task != null) - { - PushTasksToWCS(new List<Dt_Task> { task }); - return WebResponseContent.Instance.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task)); - } - - if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && stationCode != "8005")//杈呮枡浠撲笉闄愬埗鍏ュ簱浠诲姟 - { - return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�"); - } - if (!string.IsNullOrEmpty(materielBoxCode)) - { - _unitOfWorkManage.BeginTran(); - WebResponseContent responseGroup = _inboundOrderService.MaterielPPorGM(materielBoxCode); - if (!responseGroup.Status) - { - return WebResponseContent.Instance.Error($"{responseGroup.Message}"); - } - Dt_StockInfo stockInfoPPorGM = responseGroup.Data as Dt_StockInfo ?? null; - if (stockInfoPPorGM==null) - { - return WebResponseContent.Instance.Error($"缁勭洏鏁版嵁杞崲澶辫触"); - } - Dt_LocationInfo? locationInfoPPorGM = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfoPPorGM.PalletType, stockInfoPPorGM.WarehouseId); - if (locationInfoPPorGM == null) - { - return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅"); - } - Dt_Task newTaskPPorGM = new Dt_Task() - { - CurrentAddress = stationCode, - Grade = 0, - NextAddress = locationInfoPPorGM.LocationCode, - PalletCode = stockInfoPPorGM.PalletCode, - Roadway = roadwayNo, - SourceAddress = stationCode, - TargetAddress = locationInfoPPorGM.LocationCode, - TaskType = TaskTypeEnum.Inbound.ObjToInt(), - TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = stockInfoPPorGM.WarehouseId, - PalletType = stockInfoPPorGM.PalletType, - TaskLength= stockInfoPPorGM.StockLength - }; - - //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗� - Dt_InboundOrder? inboundOrderPPorGM = null; - if (stockInfoPPorGM != null && stockInfoPPorGM.Details.Count > 0) - { - string? orderNo = stockInfoPPorGM.Details.FirstOrDefault()?.OrderNo ?? ""; - inboundOrderPPorGM = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()); - } - - if (inboundOrderPPorGM != null) - { - if (inboundOrderPPorGM.OrderType == InOrderTypeEnum.Allocat.ObjToInt()) - { - newTaskPPorGM.TaskType = TaskTypeEnum.InAllocate.ObjToInt(); - } - else if (inboundOrderPPorGM.OrderType == InOrderTypeEnum.Return.ObjToInt()) - { - newTaskPPorGM.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt(); - } - } - stockInfoPPorGM.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - LocationStatusEnum lastStatusPPorGM = (LocationStatusEnum)locationInfoPPorGM.LocationStatus; - _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfoPPorGM, lastStatusPPorGM, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation); - _basicService.LocationInfoService.UpdateLocationStatus(locationInfoPPorGM, newTaskPPorGM.PalletType, LocationStatusEnum.Lock, newTaskPPorGM.WarehouseId); - int taskIdPPorGM = BaseDal.AddData(newTaskPPorGM); - newTaskPPorGM.TaskId = taskIdPPorGM; - _stockRepository.StockInfoRepository.Db.InsertNav(stockInfoPPorGM).Include(x => x.Details).ExecuteCommand(); - _unitOfWorkManage.CommitTran(); - WMSTaskDTO wMSTaskDTOPPorGM = _mapper.Map<WMSTaskDTO>(newTaskPPorGM); - - PushTasksToWCS(new List<Dt_Task> { newTaskPPorGM }); - return WebResponseContent.Instance.OK(data: wMSTaskDTOPPorGM); - } - Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First(); - if (stockInfo == null) - { - return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�"); - } - if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt()) - { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱"); - } - if (!string.IsNullOrEmpty(stockInfo.LocationCode)) - { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅"); - } - - Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfo.PalletType, stockInfo.WarehouseId); - if (locationInfo == null) - { - return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅"); - } - - Dt_Task newTask = new Dt_Task() - { - CurrentAddress = stationCode, - Grade = 0, - NextAddress = locationInfo.LocationCode, - PalletCode = palletCode, - Roadway = roadwayNo, - SourceAddress = stationCode, - TargetAddress = locationInfo.LocationCode, - TaskType = TaskTypeEnum.Inbound.ObjToInt(), - TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = stockInfo.WarehouseId, - PalletType = stockInfo.PalletType, - }; - - //鑾峰彇鏄惁瀛樺湪鍏ュ簱鍗� - Dt_InboundOrder? inboundOrder = null; - if (stockInfo != null && stockInfo.Details.Count > 0) - { - string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; - inboundOrder = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()); - } - - if (inboundOrder != null) - { - if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt(); - } - else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt(); - } - } - if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt()) - { - stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(); - } - else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt(); - } - else if (stockInfo.StockStatus == StockStatusEmun.鎷i�夊畬鎴�.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.InPick.ObjToInt(); - } - else - { - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - } - - LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; - _unitOfWorkManage.BeginTran(); - _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation); - _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, newTask.PalletType, LocationStatusEnum.Lock, newTask.WarehouseId); - int taskId = BaseDal.AddData(newTask); - newTask.TaskId = taskId; - _stockRepository.StockInfoRepository.UpdateData(stockInfo); - _unitOfWorkManage.CommitTran(); - WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask); - - PushTasksToWCS(new List<Dt_Task> { newTask }); - if (newTask.WarehouseId == 5) PutFinish(stationCode.ToString(),newTask.PalletCode, newTask.TaskNum.ToString()); - return WebResponseContent.Instance.OK(data: wMSTaskDTO); - } - catch (Exception ex) - { - _unitOfWorkManage.RollbackTran(); - return WebResponseContent.Instance.Error(ex.Message); - } - } - /// <summary> /// 浠呯敵璇蜂换鍔★紝璁¦CS鏍规嵁璺敱纭畾涓嬩竴鍦板潃 /// </summary> @@ -547,56 +120,51 @@ return WebResponseContent.Instance.Error(ex.Message); } } - /// <summary> - /// + /// 鍘熸枡鐢宠鍏ュ簱 /// </summary> - /// <param name="stationCode"></param> - /// <param name="palletCode"></param> - /// <param name="staions"></param> - /// <param name="heightType"></param> + /// <param name="stationCode">璧峰绔欑偣</param> + /// <param name="palletCode">鎵樼洏</param> /// <returns></returns> - public WebResponseContent DeviceRequestInboundTaskByRoadways(string stationCode, string palletCode, List<string> staions, int heightType) + public WebResponseContent RequestYLWMSTaskSimple(string stationCode, string palletCode) { + WebResponseContent content = new WebResponseContent(); try { Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode); if (task != null) { PushTasksToWCS(new List<Dt_Task> { task }); - return WebResponseContent.Instance.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task)); + return content.OK($"璇ユ墭鐩樺凡鐢熸垚浠诲姟", _mapper.Map<WMSTaskDTO>(task)); } if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null) { - return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�"); + return content.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�"); } - - string roadwayNo = AssignRoadwayNo(staions, palletCode, heightType); - Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode); if (stockInfo == null) { - return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�"); + return content.Error($"鏈壘鍒扮粍鐩樹俊鎭�"); } - if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鎷i�夊畬鎴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt()) + if (stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt()) { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱"); + return content.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱"); } - if (!string.IsNullOrEmpty(stockInfo.LocationCode)) + string rowWay = AssignYLRoadwayNo(stockInfo.PalletCode); + if (string.IsNullOrEmpty(rowWay)) { - return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅"); + return content.Error($"鏈壘鍒板彲鍒嗛厤宸烽亾"); } - Dt_Task newTask = new Dt_Task() { CurrentAddress = stationCode, Grade = 0, NextAddress = "", PalletCode = palletCode, - Roadway = roadwayNo, + Roadway = rowWay, SourceAddress = stationCode, - TargetAddress = roadwayNo, + TargetAddress = "", TaskType = TaskTypeEnum.Inbound.ObjToInt(), TaskStatus = TaskStatusEnum.New.ObjToInt(), WarehouseId = stockInfo.WarehouseId, @@ -607,25 +175,126 @@ { stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(); } - else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt()) - { - newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt(); - } - else - { - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - } - _unitOfWorkManage.BeginTran(); int taskId = BaseDal.AddData(newTask); newTask.TaskId = taskId; _stockRepository.StockInfoRepository.UpdateData(stockInfo); _unitOfWorkManage.CommitTran(); - WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask); - PushTasksToWCS(new List<Dt_Task> { newTask }); - //if (newTask.WarehouseId == 5) PutFinish(stationCode); - return WebResponseContent.Instance.OK(data: wMSTaskDTO); + WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask); + return content.OK(data: wMSTaskDTO); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + content.Error(ex.Message); + } + return content; + } + public string AssignYLRoadwayNo(string palletCode) + { + try + { + Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode); + if (stockInfo==null) + { + throw new Exception($"缁勭洏搴撳瓨涓嶅瓨鍦�"); + } + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == stockInfo.WarehouseId); + + if (warehouse == null) + { + throw new Exception($"鏈壘鍒板贩閬撳搴斾粨搴撲俊鎭�"); + } + + string roadwayNo = ""; + if (stockInfo.MaterielThickness > 800) + { + List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && 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.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo=="SC02_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("鏈壘鍒板彲鍒嗛厤宸烽亾"); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + 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() || x.StationArea == AGVStationAreaEnum.AreaC.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(); + if (task.TaskType == TaskTypeEnum.InPick.ObjToInt()) + { + Dt_LocationInfo locationInfoStart = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + _basicService.LocationInfoService.UpdateLocationStatus(locationInfoStart, stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId); + } + 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) { @@ -633,7 +302,43 @@ return WebResponseContent.Instance.Error(ex.Message); } } + /// <summary> + /// 鍒嗛厤鎴愬搧宸烽亾 + /// </summary> + /// <returns></returns> + public string AssignCPRoadwayNo() + { + try + { + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == 2); + if (warehouse == null) + { + throw new Exception($"鏈壘鍒板贩閬撳搴斾粨搴撲俊鎭�"); + } + string roadwayNo = ""; + List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && 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(); + //绛涢�夊綋鍓嶅叆搴撲换鍔′腑宸插垎閰嶅贩閬撲换鍔℃暟閲� + 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) + { + _unitOfWorkManage.RollbackTran(); + throw new Exception(ex.Message); + } + } /// <summary> /// 鍏ュ簱浠诲姟鐢宠鍒嗛厤璐т綅 /// </summary> @@ -654,7 +359,7 @@ { return WebResponseContent.Instance.OK(data: task.TargetAddress); } - + //鍒嗛厤璐т綅 Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId); if (locationInfo == null) { @@ -674,7 +379,7 @@ LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; - + //鏇存柊閿佸畾璐т綅 _unitOfWorkManage.BeginTran(); _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation); _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId); @@ -736,30 +441,27 @@ return WebResponseContent.Instance.Error(ex.Message); } } - public readonly string[] OutStartPonits = { "5230", "5237", "5244" }; /// <summary> - /// 鎴愬搧浣欐枡閫�搴撳叆浠� + /// 绌烘鍥炲簱 /// </summary> - /// <param name="barCode"></param> - /// <param name="startPoint"></param> - /// <returns></returns> - public WebResponseContent BackProductTask(string barCode, string startPoint) + public WebResponseContent EmptyBackTask(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)) + //string palletCode = @"^C\d{5}$"; // 姝e垯琛ㄨ揪寮� + //bool isValid = Regex.IsMatch(barCode, palletCode); + //if (!isValid) + //{ + // return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}"); + //} + Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x=>x.AGVStationCode==startPoint); + if (agvstation==null) { 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())); + Dt_Task taskOldPoint = BaseDal.QueryFirst(x => x.SourceAddress == startPoint &&( x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus==TaskStatusEnum.AGV_Executing.ObjToInt())); if (taskOldPoint != null) { return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�"); @@ -767,76 +469,128 @@ Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode); if (taskOld != null) { - return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�"); + 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) + Dt_ProStockInfo proStockInfoOld = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode); + if (proStockInfoOld!=null) { - return content.Error($"鏈壘鍒皗barCode}鑳舵淇℃伅"); + return content.Error($"鎵樼洏{barCode}宸插瓨鍦�"); } - if (proStockInfo.proStockInfoDetails==null || proStockInfo.proStockInfoDetails.Count<=0) + //鍒嗛厤宸烽亾 + string roadWay=AssignCPRoadwayNo(); + + //鑾峰彇鎴愬搧搴� + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.LLDCP.ToString()); + Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo() { - 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(); - }); + PalletCode=barCode, + ProStockAttribute=ProStockAttributeEnum.绌烘墭.ObjToInt(), + PalletType=1, + LocationCode="", + WarehouseId=warehouse.WarehouseId, + StockStatus=StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt() + }; + Dt_Task newTask = new Dt_Task() { CurrentAddress = startPoint, Grade = 0, NextAddress = "", - PalletCode = proStockInfo.PalletCode, - Roadway = locationInfo.RoadwayNo, + PalletCode = barCode, + Roadway = roadWay, SourceAddress = startPoint, TargetAddress = "", - TaskType = TaskTypeEnum.InProductBack.ObjToInt(), + TaskType = TaskTypeEnum.EmptyProductBack.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) + WarehouseId = warehouse.WarehouseId, + PalletType = 1 }; _unitOfWorkManage.BeginTran(); int taskId = BaseDal.AddData(newTask); + _stockRepository.ProStockInfoRepository.AddData(proStockInfo); newTask.TaskId = taskId; - _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo); - _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails); + _unitOfWorkManage.CommitTran(); + //鎺ㄩ�佷换鍔� + PushTasksToWCS(new List<Dt_Task> { newTask },"AGV"); + content.OK("鍙戦�佹垚鍔�"); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + content.Error(ex.Message); + } + return content; + } + /// <summary> + /// 鍗板埛浣欐枡閫�鏂欎换鍔� + /// </summary> + public WebResponseContent PrintBackInbound(SaveModel saveModel) + { + WebResponseContent content = new WebResponseContent(); + try + { + var barcode = saveModel.MainData["palletCode"].ToString(); + var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); + var materSn = saveModel.MainData["materSn"]; + //鐩村緞 + var thickness = saveModel.MainData["thickness"].ObjToInt(); + var weight = saveModel.MainData["weight"].ObjToInt(); + var address = saveModel.MainData["address"].ToString(); + //骞呭 + var wide = saveModel.MainData["wide"].ObjToInt(); + Dt_MaterielInfo? materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materSn); + if (materielInfo == null) + { + return content.Error("鏈壘鍒扮墿鏂欎俊鎭�"); + } + Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode); + if (stockInfoOld != null) + { + return content.Error("鎵樼洏淇℃伅宸插瓨鍦�"); + } + //鐢熸垚搴撳瓨缁勭洏淇℃伅 + Dt_StockInfo stockInfo = new Dt_StockInfo() + { + MaterielInvOrgId = materielInfo.MaterielInvOrgId, + PalletCode = barcode, + LocationCode = "", + PalletType = 1, + WarehouseId = warehouseId, + StockAttribute = materielInfo.MaterielSourceType, + StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(), + MaterielSpec = materielInfo.MaterielSpec, + Unit = materielInfo.MaterielUnit, + MaterielThickness = thickness, + MaterielWide = wide, + MaterielWeight = weight, + MaterielCode = materielInfo.MaterielCode, + MaterielName = materielInfo.MaterielName, + }; + if (wide > 1200) + { + stockInfo.PalletType = 2; + } + + //鐢熸垚鍗板埛浣欐枡閫�鏂欎换鍔� + Dt_Task newTask = new Dt_Task() + { + CurrentAddress = address, + Grade = 0, + NextAddress = "", + PalletCode = barcode, + Roadway = "", + SourceAddress = address, + TargetAddress = "", + TaskType = TaskTypeEnum.PrintBackInbound.ObjToInt(), + TaskStatus = TaskStatusEnum.New.ObjToInt(), + WarehouseId = warehouseId, + PalletType = 1, + TaskLength= wide + }; + _unitOfWorkManage.BeginTran(); + int taskId = BaseDal.AddData(newTask); + _stockRepository.StockInfoRepository.AddData(stockInfo); + newTask.TaskId = taskId; _unitOfWorkManage.CommitTran(); //鎺ㄩ�佷换鍔� PushTasksToWCS(new List<Dt_Task> { newTask }); @@ -850,66 +604,78 @@ return content; } /// <summary> - /// 绌烘鍥炲簱 + /// 鍗板埛涓嬫枡浠诲姟 /// </summary> - public WebResponseContent EmptyBackTask(string barCode, string startPoint) + public WebResponseContent PrintInbound(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { - string palletCode = @"^C\d{5}$"; // 姝e垯琛ㄨ揪寮� - bool isValid = Regex.IsMatch(barCode, palletCode); - if (!isValid) + var barcode = saveModel.MainData["palletCode"].ToString(); + var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); + var materSn = saveModel.MainData["materSn"]; + //鐩村緞 + var thickness = saveModel.MainData["thickness"].ObjToInt(); + var weight = saveModel.MainData["weight"].ObjToInt(); + var address = saveModel.MainData["address"].ToString(); + //骞呭 + var wide = saveModel.MainData["wide"].ObjToInt(); + Dt_MaterielInfo? materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materSn); + if (materielInfo == null) { - return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}"); + return content.Error("鏈壘鍒扮墿鏂欎俊鎭�"); } - if (!OutStartPonits.Contains(startPoint)) + if (materielInfo.MaterielSourceType!=MaterielTypeEnum.鍗婃垚鍝�.ObjToInt()) { - return content.Error($"璧风偣閿欒{startPoint}"); + return content.Error($"鏈壘鍒扮墿鏂檣materielInfo.MaterielCode}鍗婃垚鍝佷俊鎭�"); } - //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅 - 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())); - //if (taskOldPoint != null) - //{ - // return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�"); - //} - Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode); - if (taskOld != null) + Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode); + if (stockInfoOld != null) { - return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�"); + return content.Error("鎵樼洏淇℃伅宸插瓨鍦�"); } - //if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null) - //{ - // return content.Error($"鑳舵{barCode}搴撳瓨淇℃伅宸插瓨鍦�"); - //} - //todo:涓存椂瑙g粦 - Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode); - if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null) + //鐢熸垚搴撳瓨缁勭洏淇℃伅 + Dt_StockInfo stockInfo = new Dt_StockInfo() { - proStockInfo.PalletCode = proStockInfo.PalletCode + ":" + DateTime.Now.ToString("MM/dd"); + MaterielInvOrgId = materielInfo.MaterielInvOrgId, + PalletCode = barcode, + LocationCode = "", + PalletType = 1, + WarehouseId = warehouseId, + StockAttribute = materielInfo.MaterielSourceType, + StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(), + MaterielSpec = materielInfo.MaterielSpec, + Unit = materielInfo.MaterielUnit, + MaterielThickness = thickness, + MaterielWide = wide, + MaterielWeight = weight, + MaterielCode = materielInfo.MaterielCode, + MaterielName = materielInfo.MaterielName, + }; + if (wide > 1200) + { + stockInfo.PalletType = 2; } - //鑾峰彇鎴愬搧骞冲簱 - Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); + + //鐢熸垚鍗板埛鍗婃垚鍝佸叆搴撲换鍔� Dt_Task newTask = new Dt_Task() { - CurrentAddress = startPoint, + CurrentAddress = address, Grade = 0, NextAddress = "", - PalletCode = barCode, - Roadway = "CL01_CP", - SourceAddress = startPoint, + PalletCode = barcode, + Roadway = "", + SourceAddress = address, TargetAddress = "", - TaskType = TaskTypeEnum.EmptyProductBack.ObjToInt(), + TaskType = TaskTypeEnum.PrintInbound.ObjToInt(), TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = warehouse.WarehouseId, - PalletType = 1 + WarehouseId = warehouseId, + PalletType = 1, + TaskLength = wide }; _unitOfWorkManage.BeginTran(); int taskId = BaseDal.AddData(newTask); - if (proStockInfo!=null) - { - _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo); - } + _stockRepository.StockInfoRepository.AddData(stockInfo); newTask.TaskId = taskId; _unitOfWorkManage.CommitTran(); //鎺ㄩ�佷换鍔� @@ -918,6 +684,7 @@ } catch (Exception ex) { + _unitOfWorkManage.RollbackTran(); content.Error(ex.Message); } return content; -- Gitblit v1.9.3