using log4net.Core; using Mapster; using Masuit.Tools; using System.Collections.Generic; using System.Threading.Tasks; using WIDESEA_Comm.AGVTask; using WIDESEA_Comm.WCSInterface.Requst; using WIDESEA_Common; using WIDESEA_Core.Const; using WIDESEA_DTO.WMS; using WIDESEA_IStorageBasicRepository; using WIDESEA_StorageBasicRepository; using WIDESEA_StorageTaskRepository; using WIDESEA_StoragIntegrationServices; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob.Models; namespace WIDESEA_StorageTaskServices; public partial class Dt_TaskService : ServiceBase, IDt_TaskService { #region 请求任务入库 /// /// 请求入库 /// /// 请求模型 /// 包含任务信息的响应内容 public async Task RequestInTask(RequestTaskDto input) { // 创建一个WebResponseContent对象 WebResponseContent content = new WebResponseContent(); try { var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); if (task != null) { throw new Exception($"托盘{input.PalletCode}已存在任务"); } var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position); if (stationInfo == null) { throw new Exception($"站台{input.Position}不存在"); } var carBody = _carBodyRepository.QueryFirst(x => x.PalletCode == input.PalletCode); if (carBody != null) throw new Exception($"空撬{input.PalletCode}信息已存在"); Dt_CarBodyInfo dt_CarBodyInfo = new Dt_CarBodyInfo { PalletCode = input.PalletCode, CarType = 3, PVI = input.PalletCode, RFID = input.PalletCode, BodyStatus = 0 }; //BDCManager bDCManager = new BDCManager(_bdcConfigurationService, _locationRepository, _roadWayInfoRepository); //await bDCManager.AddToBDC(carBody); // 获取库位 var location = RequestLocation(stationInfo.RoadwayNo, 3); if (location == null) { return content.Error("无法获取货位信息或库位已满"); } var newtask = new Dt_Task { CurrentAddress = input.Position, Grade = 1, Roadway = stationInfo.Roadway, TargetAddress = location.LocationCode, //Dispatchertime = DateTime.Now, NextAddress = input.Position, OrderNo = null, PalletCode = input.PalletCode, SourceAddress = stationInfo.stationLocation, TaskState = (int)TaskInStatusEnum.InNew, TaskType = (int)TaskInboundTypeEnum.InTray, TaskNum = await BaseDal.GetTaskNo(), Creater = "Systeam", PVI = input.PVI, }; _unitOfWorkManage.BeginTran(); BaseDal.AddData(newtask); _carBodyRepository.AddData(dt_CarBodyInfo); location.LocationStatus = (int)LocationEnum.InStockDisable; _locationRepository.UpdateData(location); _unitOfWorkManage.CommitTran(); content.OK("申请入库成功", data: newtask); } catch (Exception er) { _unitOfWorkManage.RollbackTran(); // 如果发生异常,则调用content.Error方法,记录错误信息,并输出错误信息 content.Error($"入库申请失败:{er.Message}"); Console.WriteLine(er.Message); } // 返回content return content; } #endregion 请求任务入库 #region 库位分配 #region 获取货位 object objLOCK = new object(); /// /// 库位分配 /// /// /// /// public DtLocationInfo RequestLocation(string roadwayNo, int carType) { lock (objLOCK) { try { List locations = new List(); if (carType == 1) { locations = _locationRepository.QueryData(x => x.RoadwayNo == roadwayNo && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1 && (x.LocationType == 1 || x.LocationType == 3)); //&& x.LocationType == 1 } else if (carType == 2) { locations = _locationRepository.QueryData(x => x.RoadwayNo == roadwayNo && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1 && (x.LocationType == 2 || x.LocationType == 3)); //&& x.LocationType == 1 } else if (carType == 3) { locations = _locationRepository.QueryData(x => x.RoadwayNo == roadwayNo && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1 && x.LocationType == 3); //&& x.LocationType == 1 } var location = GetEmptyLocation(locations, carType); if (location == null) { throw new Exception("库位已满"); } return location; } catch (Exception err) { Console.WriteLine(err.Message.ToString()); return null; } } } private DtLocationInfo GetEmptyLocation(List dtLocationInfos, int carType) { DtLocationInfo locationinfo = new DtLocationInfo(); if (carType == 1 || carType == 3) { locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); } else if (carType == 2) { locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); } //else if (carType == 3) //{ // locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).OrderBy(x => x.Column).ThenBy(x => x.Row).ThenBy(x => x.Layer).FirstOrDefault(); //} return locationinfo; } #endregion 获取货位 #endregion 库位分配 //public WebResponseContent }