using System; using System.Collections.Generic; using System.Text; using WIDESEA.Common; using WIDESEA.Core.ManageUser; using WIDESEA.Core.Services; using WIDESEA.Core.Utilities; using WIDESEA.Entity.DomainModels; using WIDESEA.Services.IRepositories; using WIDESEA.Services.Repositories; namespace WIDESEA.Services.Services { public partial class CommonFunction { /// /// 移库出库 /// /// /// public static WebResponseContent MoveContainerAction(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { string barcode = saveModel.MainData["barcode"].ToString(); string targetLocation = saveModel.MainData["targetLocation"].ToString(); string moveType = saveModel.MainData["moveType"].ToString(); string locationId = string.Empty; string materielId = string.Empty; if ("Empty".Equals(moveType)) { VV_ContainerInfo_EmptyPallet emptyContainer = VV_ContainerInfo_EmptyPalletRepository.Instance.FindFirst(r => r.containerdtl_barcode == barcode); if (null == emptyContainer) return content.Error("获取库存信息失败."); if (emptyContainer.location_islocked || emptyContainer.location_state != LocationState.LocationState_Stored.ToString()) return content.Error("当前库存信息非在库状态或锁定状态."); locationId = emptyContainer.location_id; materielId = emptyContainer.materiel_id; } else { VV_ContainerInfo container = VV_ContainerInfoRepository.Instance.FindFirst(r => r.containerdtl_barcode == barcode); if (null == container) return content.Error("获取库存信息失败."); if (container.location_islocked || container.location_state != LocationState.LocationState_Stored.ToString()) return content.Error("当前库存信息非在库状态或锁定状态."); locationId = container.location_id; materielId = container.materiel_id; } Dt_locationinfo newLocation = Dt_locationinfoRepository.Instance.FindFirst(r => r.location_id == targetLocation.Trim()); if (null == newLocation) return content.Error("获取新货位信息失败."); if (newLocation.location_islocked || newLocation.location_state != LocationState.LocationState_Empty.ToString()) return content.Error("新货位非空货位状态或锁定状态."); IDt_taskinfoRepository taskinfoRepository = Dt_taskinfoRepository.Instance; content = taskinfoRepository.DbContextBeginTransaction(() => { Dt_locationinfo locationinfo = Dt_locationinfoRepository.Instance.FindFirst(x => x.location_id == locationId); CommonFunction.ChangeLocationState(locationinfo, LocationState.LocationState_MoveOutbound.ToString()); CommonFunction.ChangeLocationState(newLocation, LocationState.LocationState_MoveInbound.ToString()); Dt_taskinfo taskinfo = new Dt_taskinfo(); taskinfo.task_id = Guid.NewGuid(); taskinfo.task_type = TaskType.TaskType_MoveOutbound.ToString(); taskinfo.task_state = TaskState.TaskState_Create.ToString(); taskinfo.task_barcode = barcode; taskinfo.task_materielid = materielId; //起始货位 taskinfo.task_fromlocationid = locationId; //目的货位 taskinfo.task_tolocationid = targetLocation; //起始站台 taskinfo.task_beginstation = LayerToStation.EmptyPalletOutLayerToStation(locationinfo.location_layer); //目的站台 taskinfo.task_endstation = LayerToStation.EmptyPalletOutLayerToStation(newLocation.location_layer); taskinfo.task_grade = 0; taskinfo.task_isunpacked = false; taskinfo.task_creator = UserContext.Current.UserTrueName; taskinfo.task_createtime = DateTime.Now; taskinfoRepository.Add(taskinfo, true); //下发出库任务给WCS content = WIDESEA_Services.WCSApi.SendTaskToWCS(new List() { taskinfo }); if (content.Status) content.OK($"移库出库任务下发给WCS成功."); else content.Error($"移库出库任务下发给WCS失败,原因 => {content.Message}"); return content; }); } catch (Exception ex) { content.Error("创建移库任务失败:" + ex.Message); } finally { Logger.AddLog(Core.Enums.LoggerType.Add, saveModel, content, content); } return content; } } }