¶Ô±ÈÐÂÎļþ |
| | |
| | | using log4net.Core; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_DTO.MOM; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IStorageBasicRepository; |
| | | using WIDESEA_IStoragIntegrationServices; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_StorageBasicRepository; |
| | | using WIDESEA_StorageTaskRepository; |
| | | using WIDESEA_StoragIntegrationServices; |
| | | |
| | | namespace WIDESEA_StorageOutTaskServices |
| | | { |
| | | public class Dt_TaskService1 : ServiceBase<Dt_Task, IDt_TaskRepository>, IDt_TaskService |
| | | { |
| | | private readonly LogFactory _logFactory = new LogFactory(); |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IDt_OutOrderRepository _outOrderRepository; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly IStockInfoDetailRepository _stockInfoDetailRepository; |
| | | private readonly IDt_Task_HtyRepository _task_HtyRepository; |
| | | private readonly IDt_OutOrderAndStockRepository _outOrderAndStockRepository; |
| | | private readonly IDt_OutOrderAndStock_HtyRepository _outOrderAndStock_HtyRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly IDt_MaterielInfoRepository _materielInfoRepository; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_WareAreaInfoRepository _wareAreaInfoRepository; |
| | | private readonly IPointStackerRelationRepository _pointStackerRelationRepository; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; |
| | | private readonly IBoxingInfoRepository _boxingInfoRepository; // ç»ç |
| | | private readonly ICellStateService _cellStateService; // çµè¯å±æ§ |
| | | private readonly IProcessApplyService _processApplyService; // å·¥èºè·¯çº¿ |
| | | private readonly IDt_AreaInfoRepository _areaInfoRepository; // åºå |
| | | private readonly IAgingInOrOutInputService _agingInOrOutInputService; // éç½®/éå |
| | | private readonly IProductionRepository _productionRepository; // ç产 |
| | | |
| | | public Dt_TaskService1(IDt_TaskRepository BaseDal, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | | IDt_OutOrderRepository outOrderRepository, |
| | | IStockInfoRepository stockInfoRepository, |
| | | IDt_OutOrderAndStockRepository dt_OutOrderAndStockRepository, |
| | | IDt_OutOrderAndStock_HtyRepository dt_OutOrderAndStock_HtyRepository, |
| | | IDt_Task_HtyRepository task_HtyRepository, |
| | | IMapper mapper, |
| | | IDt_MaterielInfoRepository materielInfoRepository, |
| | | ILocationInfoRepository locationRepository, |
| | | IDt_WareAreaInfoRepository wareAreaInfoRepository, |
| | | IPointStackerRelationRepository pointStackerRelationRepository, |
| | | ITaskExecuteDetailRepository taskExecuteDetailRepository, |
| | | ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, |
| | | IBoxingInfoRepository boxingInfoRepository, |
| | | ICellStateService cellStateService, |
| | | IProcessApplyService processApplyService, |
| | | IDt_AreaInfoRepository areaInfoRepository, |
| | | IAgingInOrOutInputService agingInOrOutInputService, |
| | | IStockInfoDetailRepository stockInfoDetailRepository, |
| | | IProductionRepository productionRepository) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _outOrderRepository = outOrderRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _outOrderAndStockRepository = dt_OutOrderAndStockRepository; |
| | | _outOrderAndStock_HtyRepository = dt_OutOrderAndStock_HtyRepository; |
| | | _task_HtyRepository = task_HtyRepository; |
| | | _mapper = mapper; |
| | | _materielInfoRepository = materielInfoRepository; |
| | | _locationRepository = locationRepository; |
| | | _wareAreaInfoRepository = wareAreaInfoRepository; |
| | | _pointStackerRelationRepository = pointStackerRelationRepository; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; |
| | | _boxingInfoRepository = boxingInfoRepository; |
| | | _cellStateService = cellStateService; |
| | | _processApplyService = processApplyService; |
| | | _areaInfoRepository = areaInfoRepository; |
| | | _agingInOrOutInputService = agingInOrOutInputService; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _productionRepository = productionRepository; |
| | | } |
| | | |
| | | // å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | #region åºåºä»»å¡å®æ |
| | | // åºåºä»»å¡å®æ |
| | | public async Task<WebResponseContent> CompleteStackTaskAsync(Dt_Task task, DtStockInfo stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) |
| | | { |
| | | var process = await SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>() |
| | | .FirstAsync(x => x.EquipmentName == task.Roadway); |
| | | var info = JsonConvert.DeserializeObject<ResponseEqptRunDto>(process.ProcessValue); |
| | | |
| | | var agingOutputDto = MapToAgingOutputDto(stock, info); |
| | | content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto); |
| | | ValidateResponse(content); |
| | | } |
| | | |
| | | // æ´æ°åºåç¶æåä»»å¡ç¶æ |
| | | (var loc, var tas) = UpdateStockAndTaskStatus(stock, task); |
| | | |
| | | // äºå¡å¤ç |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await UpdateLocationAsync(loc); |
| | | await DeleteStockInfoAsync(stock.Id); |
| | | await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); |
| | | //await DeleteTaskAsync(task.TaskId); |
| | | }); |
| | | |
| | | return content.OK("ä»»å¡å®ææå"); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | _logFactory.GetLog("ä»»å¡å®æ").Error(true, $"ç³»ç»å¼å¸¸ï¼å¼å¸¸ä¿¡æ¯ï¼{err.Message}"); |
| | | return content.Error(err.Message); |
| | | } |
| | | } |
| | | |
| | | // æ å°å°èåè¾åºDTO |
| | | private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, ResponseEqptRunDto info) |
| | | { |
| | | // TODO Value弿 ¹æ®MOMä¸åçéç½®æ¶é´å°å½åæ¶é´çåéæ° |
| | | return new AgingOutputDto |
| | | { |
| | | OpFlag = 1, |
| | | Software = "WMS", |
| | | EquipmentCode = "ECH001-B", |
| | | TrayBarcode = stock.PalletCode, |
| | | SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto |
| | | { |
| | | SlotNo = x.OrderNo.ToInt32(), |
| | | SerialNo = x.SerialNumber, |
| | | SerialNoResult = true, |
| | | ParameterInfo = info.ParameterInfo.Select(y => new ParameterInfo |
| | | { |
| | | LowerLomit = y.LowerControlLimit, |
| | | UpperLimit = y.UpperControlLimit, |
| | | ParameterResult = y.EquipmentAvailabilityFlag, |
| | | ParameterCode = y.ParameterCode, |
| | | ParameterDesc = y.Description, |
| | | TargetValue = y.TargetValue, |
| | | Value = (DateTime.Parse(stock.LinedProcessFeedbackTime, null, System.Globalization.DateTimeStyles.RoundtripKind).ToLocalTime() - stock.CreateDate).TotalMinutes.ToString(), |
| | | DefectCode = y.UOMCode |
| | | }).ToList() |
| | | }).ToList() |
| | | }; |
| | | } |
| | | |
| | | // éªè¯ååºå
容 |
| | | private void ValidateResponse(WebResponseContent content) |
| | | { |
| | | var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString()); |
| | | if (!result.Success) |
| | | { |
| | | throw new Exception(result.MOMMessage); |
| | | } |
| | | } |
| | | |
| | | // æ´æ°åºåç¶æåä»»å¡ç¶æ |
| | | private (DtLocationInfo, Dt_Task) UpdateStockAndTaskStatus(DtStockInfo stock, Dt_Task task) |
| | | { |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); |
| | | var details = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id); |
| | | |
| | | location.LocationStatus = (int)LocationEnum.Free; |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | | //task.CurrentAddress = task.NextAddress; |
| | | //task.NextAddress = task.TargetAddress; |
| | | |
| | | _logFactory.GetLog("ä»»å¡å®æ").Info(true, "æ´æ°åºåç¶æä¸ä»»å¡ç¶æ"); |
| | | return (location, task); |
| | | } |
| | | |
| | | // å é¤åºåä¿¡æ¯ |
| | | private async Task DeleteStockInfoAsync(int stockId) |
| | | { |
| | | var isStockUpdated = await _stockInfoRepository.DeleteDataByIdAsync(stockId); |
| | | if (!isStockUpdated) |
| | | { |
| | | throw new Exception("åºåä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | // æ´æ°åºåä½ç½® |
| | | private async Task UpdateLocationAsync(DtLocationInfo info) |
| | | { |
| | | var isStockUpdated = await _locationRepository.UpdateDataAsync(info); |
| | | if (!isStockUpdated) |
| | | { |
| | | throw new Exception("åºåä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | // å é¤åºå详æ
ä¿¡æ¯ |
| | | private async Task DeleteStockInfoDetailsAsync(IEnumerable<DtStockInfoDetail> details) |
| | | { |
| | | var ids = details.Select(x => (object)x.Id).ToArray(); |
| | | var isStockDetailUpdated = await _stockInfoDetailRepository.DeleteDataByIdsAsync(ids); |
| | | if (!isStockDetailUpdated) |
| | | { |
| | | throw new Exception("åºå详æ
ä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | // å é¤ä»»å¡ |
| | | private async Task<bool> DeleteTaskAsync(int taskId) |
| | | { |
| | | var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(taskId); |
| | | if (!isTaskUpdated) |
| | | { |
| | | throw new Exception("ä»»å¡ä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | } |
| | | return isTaskUpdated; |
| | | } |
| | | |
| | | #region ç§»åºä»»å¡å®æ |
| | | // ç§»åºä»»å¡å®æ |
| | | public async Task<WebResponseContent> CompleteTransferTaskAsync(Dt_Task task, DtStockInfo stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // æ´æ°è´§ä½ååºåä¿¡æ¯ |
| | | (DtStockInfo updateStock, DtLocationInfo locationInf) = UpdateStockLocation(stock, task.NextAddress); |
| | | var taskHty = CreateHistoricalTask(task); |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "ç§»åºä»»å¡å®æ", $"è´§ä½å°åï¼{task.TargetAddress},ä¿®æ¹ååºåæ°æ®ï¼{JsonConvert.SerializeObject(updateStock)}ï¼åå
è´§ä½æ°æ®ï¼{locationInf}"); |
| | | |
| | | // æ§è¡æ°æ®åºäºå¡ |
| | | bool isResult = await ExecuteTransaction(updateStock, taskHty, locationInf, task.TaskId); |
| | | if (isResult) |
| | | content.OK("ç§»åºä»»å¡å®ææå"); |
| | | else |
| | | content.Error("ç§»åºä»»å¡å®æå¤±è´¥"); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | Console.WriteLine(err.Message.ToString()); |
| | | } |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | // æ´æ°åºåä½ç½® |
| | | private (DtStockInfo, DtLocationInfo) UpdateStockLocation(DtStockInfo stock, string toLocation) |
| | | { |
| | | var locationInfo = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode); |
| | | locationInfo.LocationStatus = LocationEnum.InStock.ObjToInt(); |
| | | |
| | | stock.LocationCode = toLocation; |
| | | stock.LocationInfo.LocationStatus = LocationEnum.InStock.ObjToInt(); |
| | | |
| | | return (stock, locationInfo); |
| | | } |
| | | |
| | | // å建åå²ä»»å¡è®°å½ |
| | | private Dt_Task_Hty CreateHistoricalTask(Dt_Task task) |
| | | { |
| | | task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt(); |
| | | task.CurrentAddress = task.NextAddress; |
| | | |
| | | var taskHty = _mapper.Map<Dt_Task_Hty>(task); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.TaskId = 0; |
| | | taskHty.OperateType = (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.SourceId = task.TaskId; |
| | | taskHty.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt(); |
| | | return taskHty; |
| | | } |
| | | |
| | | // æ§è¡æ°æ®åºäºå¡ |
| | | private async Task<bool> ExecuteTransaction(DtStockInfo stock, Dt_Task_Hty taskHty, DtLocationInfo locationInfo, int taskId) |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | | { |
| | | var isUpdateStock = true; |
| | | if (taskHty.TaskType == (int)TaskTypeEnum.Outbound) |
| | | { |
| | | // æ´æ°åºå |
| | | isUpdateStock = await _stockInfoRepository.UpdateDataAsync(stock); |
| | | } |
| | | else |
| | | { |
| | | // æ·»å åºå |
| | | isUpdateStock = await _stockInfoRepository.AddDataNavAsync(stock); |
| | | } |
| | | |
| | | // æ·»å åå²ä»»å¡ |
| | | var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0; |
| | | |
| | | // ä¿®æ¹ç§»åºåè´§ä½ç¶æ |
| | | var isUpdateLoc = _locationRepository.UpdateData(locationInfo); |
| | | |
| | | // å é¤ä»»å¡æ°æ® |
| | | var isTaskDelete = await DeleteTaskAsync(taskId); |
| | | |
| | | // æäº¤æåæ»äºå¡ |
| | | if (isUpdateStock && isTaskHtyAdd && isTaskDelete && isUpdateLoc) |
| | | { |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "ä»»å¡å®æ", $"äºå¡å¤ç宿,æäº¤äºå¡ãæ·»å åå²ä»»å¡ï¼{isTaskHtyAdd},å é¤ä»»å¡æ°æ®ï¼{isTaskDelete},æ´æ°ææ·»å åºåï¼{isUpdateStock},ä¿®æ¹ç§»åºåè´§ä½ç¶æï¼{isUpdateLoc}"); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "ä»»å¡å®æ", $"æ°æ®å¤ç失败,è¯·æ£æ¥æ°æ®æ¯å¦æ£ç¡®,æ°æ®åæ»ãæ·»å åå²ä»»å¡ï¼{isTaskHtyAdd},å é¤ä»»å¡æ°æ®ï¼{isTaskDelete},æ´æ°åºåï¼{isUpdateStock},ä¿®æ¹ç§»åºåè´§ä½ç¶æï¼{isUpdateLoc}"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return false; |
| | | } |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, $"ç§»åºä»»å¡å®æ,ç³»ç»å¼å¸¸ï¼å¼å¸¸ä¿¡æ¯ï¼{err.Message}", "æ åæ°"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | throw; // æåºå¼å¸¸ä»¥ä¾¿å¤é¨æè· |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å
¥åºä»»å¡å®æ |
| | | // å
¥åºä»»å¡å®æ |
| | | public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task) |
| | | { |
| | | // åå§åååºå
容 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // è·åè£
箱信æ¯åç®æ ä½ç½®ä¿¡æ¯ |
| | | var boxing = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode); |
| | | var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress); |
| | | |
| | | // æ´æ°ç®æ ä½ç½®ç¶æä¸ºåºåä¸ |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | |
| | | // å建åå²ä»»å¡å®ä¾æ¨¡å |
| | | var taskHty = CreateHistoricalTask(task); |
| | | |
| | | // æ ¹æ®æ¯å¦æç»çä¿¡æ¯å建åºåå®ä¾æ¨¡å |
| | | DtStockInfo stock = boxing == null ? CreateEmptyPalletStock(task, locationInf) : CreateFullPalletStock(task, locationInf, boxing); |
| | | |
| | | // æ§è¡æ°æ®åºäºå¡ |
| | | bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId); |
| | | if (isResult) |
| | | { |
| | | content.OK("å
¥åºä»»å¡å®ææå"); |
| | | } |
| | | else |
| | | { |
| | | content.Error("å
¥åºä»»å¡å®æå¤±è´¥"); |
| | | } |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | // è®°å½å¼å¸¸ä¿¡æ¯å°æ§å¶å°åæ¥å¿ |
| | | Console.WriteLine(err.Message.ToString()); |
| | | _logFactory.GetLog("ä»»å¡å®æ").Error(true, err); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | // å建空æççåºåå®ä¾æ¨¡å |
| | | private DtStockInfo CreateEmptyPalletStock(Dt_Task task, DtLocationInfo locationInf) |
| | | { |
| | | return new DtStockInfo() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | LocationCode = task.TargetAddress, |
| | | CreateDate = DateTime.Now, |
| | | Creater = "system", |
| | | IsFull = false, |
| | | AreaCode = task.Roadway, |
| | | StockInfoDetails = new List<DtStockInfoDetail>() |
| | | { |
| | | new DtStockInfoDetail() |
| | | { |
| | | MaterielCode = "空æç", |
| | | Id = 0, |
| | | Status = (int)StockStateEmun.å·²å
¥åº |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | |
| | | // å建å®ççåºåå®ä¾æ¨¡åå¹¶è°ç¨MOMå
¥åº |
| | | private DtStockInfo CreateFullPalletStock(Dt_Task task, DtLocationInfo locationInf, DtBoxingInfo boxing) |
| | | { |
| | | var boxDetail = boxing.BoxingInfoDetails.Adapt<List<DtStockInfoDetail>>(); |
| | | boxDetail.ForEach(x => { x.Status = (int)StockStateEmun.å·²å
¥åº; }); |
| | | var stock = new DtStockInfo() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | LocationCode = task.TargetAddress, |
| | | CreateDate = DateTime.Now, |
| | | Creater = "system", |
| | | IsFull = boxing.IsFull, |
| | | AreaCode = task.Roadway, |
| | | StockInfoDetails = boxDetail, |
| | | }; |
| | | |
| | | // å¤ç请æ±åæ° |
| | | AgingInputDto agingInputDto = new AgingInputDto() |
| | | { |
| | | SerialNos = boxing.BoxingInfoDetails |
| | | .Select(item => new SerialNoInDto { SerialNo = item.SerialNumber, PositionNo = item.OrderNo }) |
| | | .ToList(), |
| | | TrayBarcode = task.PalletCode, |
| | | OpFlag = 1, |
| | | EquipmentCode = "ECH001-B", |
| | | Software = "WMS" |
| | | }; |
| | | var result = _agingInOrOutInputService.GetOCVInputAsync(agingInputDto).Result; |
| | | var respone = JsonConvert.DeserializeObject<ResponeAgingInputDto>(result.Data.ToString()); |
| | | stock.LinedProcessFeedbackTime = respone.LinedProcessFeedbackTime; |
| | | stock.SpecialParameterDuration = respone.SpecialParameterDuration; |
| | | //2024å¹´11æ16æ¥ï¼æ°å¢å段计ç®åºåºåºæ¶é´ |
| | | stock.OutboundTime = Convert.ToDateTime(respone.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(respone.SpecialParameterDuration)); |
| | | |
| | | // è®°å½æ¥å¿ |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "å
¥åºä»»å¡å®æ", $"è´§ä½å°åï¼{task.TargetAddress},ä¿®æ¹åè´§ä½æ°æ®ï¼{locationInf}"); |
| | | |
| | | return stock; |
| | | } |
| | | #endregion |
| | | |
| | | #region å®æä»»å¡ |
| | | // å®æä»»å¡ |
| | | public async Task<WebResponseContent> CompleteAsync(int taskNum) |
| | | { |
| | | // åå§åååºå
容 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | // æå任塿°æ® |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "æå任塿°æ®", $"ä»»å¡å·ï¼{taskNum}"); |
| | | |
| | | // éªè¯ä»»å¡æ¯å¦åå¨ |
| | | var task = await GetByTaskNum(taskNum); |
| | | if (task == null) |
| | | { |
| | | return content.Error("ä»»å¡ä¸åå¨"); |
| | | } |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "éªè¯ä»»å¡æ¯å¦åå¨", JsonConvert.SerializeObject(task)); |
| | | |
| | | // éªè¯åºåæ¯å¦åå¨ |
| | | var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode); |
| | | |
| | | // æ ¹æ®ä»»å¡ç±»åè°ç¨ç¸åºç宿任塿¹æ³ |
| | | switch (task.TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | case (int)TaskInboundTypeEnum.InTray: |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "å
¥åºä»»å¡", ""); |
| | | return await CompleteInboundTaskAsync(task); |
| | | |
| | | case (int)TaskOutboundTypeEnum.OutTray: |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | _logFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "åºåºä»»å¡", ""); |
| | | return await CompleteStackTaskAsync(task, stock); |
| | | |
| | | default: |
| | | return content.Error("ä»»å¡ç±»åä¸åå¨"); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region å
¥åºä»»å¡è¯·æ± |
| | | // 请æ±ä»»å¡å··é |
| | | public async Task<WebResponseContent> RequestTaskAsync(RequestTaskDto input) |
| | | { |
| | | // å建ä¸ä¸ªWebResponseContent对象 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | try |
| | | { |
| | | // è°ç¨BaseDal.QueryFirstAsyncæ¹æ³ï¼æ¥è¯¢ä»»å¡ |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); |
| | | if (task != null) |
| | | { |
| | | //if (task.TaskState == (int)TaskInStatusEnum.InNew) |
| | | { |
| | | // å建WMSä»»å¡ |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = 1, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.Roadway, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | }; |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | } |
| | | |
| | | // å建ä¸ä¸ªTrayCellsStatusDto对象ï¼å¹¶èµå¼ |
| | | TrayCellsStatusDto trayCells = new TrayCellsStatusDto() |
| | | { |
| | | Software = "WMS", |
| | | TrayBarcode = input.PalletCode, |
| | | //EquipmentCode = "EQ_CWJZ01" |
| | | EquipmentCode = "ECH001-B" |
| | | }; |
| | | |
| | | // è°ç¨GetTrayCellStatusAsyncæ¹æ³ï¼è·åæ´ççµè¯ |
| | | content = await GetTrayCellStatusAsync(trayCells); |
| | | // å¦æç¶æä¸ºfalseï¼åè¿åcontent |
| | | if (!content.Status) return content; |
| | | |
| | | // æ·»å ç»çä¿¡æ¯ |
| | | // å°content.Data转æ¢ä¸ºResultTrayCellsStatus对象 |
| | | var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); |
| | | if (result.SerialNos.Count <= 0) |
| | | return content.Error(result.MOMMessage); |
| | | |
| | | // TODO è·åæ¬å°ææ¡å±æ§ä¸æ´ççµè¯å±æ§è·åçå¼è¿è¡å¯¹æ¯ï¼å¦æä¸è´åç»§ç»ï¼å¦åè¿åéè¯¯ä¿¡æ¯ |
| | | //var productions = await _productionRepository.QueryDataAsync(x => result.TrayBarcodePropertys.Select(x => x.TrayBarcodeProperty).ToList().Contains(x.TrayBarcodeProperty)); |
| | | //if (productions.Count <= 0) |
| | | // return content.Error("ææ¡å±æ§ä¸åå¨"); |
| | | |
| | | // è°ç¨CreateBoxingInfoæ¹æ³ï¼å建ç»çä¿¡æ¯ |
| | | |
| | | var boxing = await CreateBoxingInfo(result, input.PalletCode); |
| | | if (boxing == null) return content.Error("ç»ç失败"); |
| | | |
| | | // è°ç¨GetProcessApplyAsyncæ¹æ³ï¼è·åå·¥èºè·¯çº¿ |
| | | ProcessApplyDto process = await GetProcessApplyAsync(result); |
| | | |
| | | // 妿process为nullï¼åè¿åcontent |
| | | if (process == null) return content; |
| | | |
| | | // è°ç¨_processApplyService.GetProcessApplyAsyncæ¹æ³ï¼è·åå·¥èºç³è¯· |
| | | content = await _processApplyService.GetProcessApplyAsync(process); |
| | | |
| | | // å¦æç¶æä¸ºfalseï¼åè¿ånull |
| | | if (!content.Status) return content.Error("å·¥èºç³è¯·å¤±è´¥"); |
| | | |
| | | // è°ç¨GetProcessResponseAsyncæ¹æ³ï¼è·åå·¥èºååº |
| | | //var processResponse = await GetProcessResponseAsync(process, input.Position); |
| | | |
| | | List<string> strings = input.Position == "1088" ? new List<string>() { "CHSC01" } : new List<string>() { "JZSC01" }; |
| | | // è°ç¨CreateNewTaskæ¹æ³ï¼å建æ°ä»»å¡ |
| | | content = await CreateNewTask(input, strings); |
| | | if (content.Status) |
| | | { |
| | | var isBox = await _boxingInfoRepository.AddDataNavAsync(boxing); |
| | | } |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | // 妿åçå¼å¸¸ï¼åè°ç¨content.Erroræ¹æ³ï¼è®°å½é误信æ¯ï¼å¹¶è¾åºéè¯¯ä¿¡æ¯ |
| | | content.Error(err.Message); |
| | | Console.WriteLine(err.Message); |
| | | } |
| | | |
| | | // è¿åcontent |
| | | return content; |
| | | } |
| | | |
| | | // 请æ±ä»»å¡è´§ä½ |
| | | public async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); |
| | | if (task == null) |
| | | return content.Error($"ææªæ¾å°ã{input.PalletCode}ãçä»»å¡"); |
| | | |
| | | return content = await UpdateExistingTask(input, task); |
| | | |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | // æ´æ°ä»»å¡è´§ä½ |
| | | private async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input, Dt_Task task) |
| | | { |
| | | if (task == null) |
| | | { |
| | | return new WebResponseContent().Error("ä»»å¡å¯¹è±¡ä¸ºç©º"); |
| | | } |
| | | |
| | | try |
| | | { |
| | | // å建WebResponseContent对象 |
| | | var content = new WebResponseContent(); |
| | | |
| | | // è·åç®æ å°ååæ´æ°ä»»å¡ç¶æ |
| | | var location = await GetLocationDistributeAsync(task.Roadway); |
| | | if (location == null) |
| | | { |
| | | return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | |
| | | string toAddress = location.LocationCode; |
| | | int taskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | int beforeStatus = location.LocationStatus; |
| | | |
| | | // æ´æ°è´§ä½ä¿¡æ¯ |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | |
| | | // æ´æ°ä»»å¡ä¿¡æ¯ |
| | | MapTaskProperties(task, input, toAddress, taskState); |
| | | |
| | | // å¼å§äºå¡ |
| | | var isResult = await UpdateTaskAsync(task, location, beforeStatus); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ´æ°ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(data: task); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // åæ»äºå¡ |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // è¿éå¯ä»¥æ·»å æ¥å¿è®°å½ |
| | | return new WebResponseContent().Error($"æ´æ°ä»»å¡æ¶åçé误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | private void MapTaskProperties(Dt_Task task, RequestTaskDto input, string toAddress, int taskState) |
| | | { |
| | | task.CurrentAddress = input.Position; |
| | | task.TargetAddress = toAddress; |
| | | task.NextAddress = toAddress; |
| | | task.TaskState = taskState; |
| | | } |
| | | |
| | | // ä¿®æ¹ä»»å¡ |
| | | private async Task<bool> UpdateTaskAsync(Dt_Task task, DtLocationInfo location, int beforeStatus) |
| | | { |
| | | bool isResult = await BaseDal.UpdateDataAsync(task); |
| | | bool isTaskDetail = await _taskExecuteDetailRepository.AddDetailAsync(task, false, TaskDescription.GetTaskUpdateDescription(task.PalletCode, task.CurrentAddress, task.TargetAddress, TaskInStatusEnum.Line_InFinish.GetIntegralRuleTypeEnumDesc())); |
| | | |
| | | LocationChangeRecordDto changeRecordDto = new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = location.LocationStatus, |
| | | BeforeStatus = beforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = location.Id, |
| | | LocationCode = location.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticStorage, |
| | | }; |
| | | |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool isUpdateLo = await _locationRepository.UpdateDataAsync(location); |
| | | |
| | | return isResult && isUpdateLo && isTaskDetail; |
| | | } |
| | | |
| | | // è·åè´§ä½ |
| | | public async Task<DtLocationInfo> GetLocationDistributeAsync(string roadWay, bool IsFull = true) |
| | | { |
| | | #region è·åè´§ä½ |
| | | |
| | | try |
| | | { |
| | | List<DtLocationInfo> locations; |
| | | if (IsFull) |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == roadWay); |
| | | } |
| | | else |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == roadWay); |
| | | } |
| | | |
| | | if (locations == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return locations.OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | Console.WriteLine(err.Message.ToString()); |
| | | return null; |
| | | } |
| | | |
| | | #endregion è·åè´§ä½ |
| | | } |
| | | #endregion |
| | | |
| | | #region 空æçå
¥åº |
| | | // 空æçå
¥åºç³è¯· |
| | | public async Task<WebResponseContent> RequestTrayInTaskAsync(RequestTaskDto input) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | // è°ç¨BaseDal.QueryFirstAsyncæ¹æ³ï¼æ¥è¯¢ä»»å¡ |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode); |
| | | if (task != null && task.TaskState == (int)TaskInStatusEnum.InNew) |
| | | { |
| | | // å建WMSä»»å¡ |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = 1, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.Roadway, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | }; |
| | | return content.OK(data: task); |
| | | } |
| | | |
| | | // è·åç®æ å°å |
| | | List<string> strings = input.Position == "1016" ? new List<string>() { "CHSC01" } : new List<string>() { "JZSC01" }; |
| | | |
| | | return await CreateNewTask(input, strings, 1); |
| | | //return await CreateNewTask(input, null, 1); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | // å建æ°ä»»å¡ |
| | | private async Task<WebResponseContent> CreateNewTask(RequestTaskDto input, List<string> process = null, int flag = 0) |
| | | { |
| | | var content = new WebResponseContent(); |
| | | |
| | | if (input == null) |
| | | { |
| | | return content.Error("è¾å
¥åæ°æ æ"); |
| | | } |
| | | |
| | | try |
| | | { |
| | | // è·åç®æ å°å |
| | | string toAddress = await GetRoadWayAsync(input, process); |
| | | |
| | | // å建æ°ä»»å¡å®ä¾ |
| | | var task = new Dt_Task |
| | | { |
| | | CurrentAddress = input.Position, |
| | | Grade = 1, |
| | | Roadway = toAddress, |
| | | TargetAddress = toAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = string.Empty, |
| | | NextAddress = toAddress, |
| | | OrderNo = null, |
| | | PalletCode = input.PalletCode, |
| | | SourceAddress = input.Position, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = flag == 0 ? (int)TaskInboundTypeEnum.Inbound : (int)TaskInboundTypeEnum.InTray, |
| | | TaskNum = await BaseDal.GetTaskNo(), |
| | | Creater = "System" // ä¿®æ£æ¼åé误 |
| | | }; |
| | | |
| | | // å°è¯æ·»å æ°ä»»å¡ |
| | | var taskId = await BaseDal.AddDataAsync(task); |
| | | if (taskId <= 0) |
| | | { |
| | | return content.Error("æ·»å ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | task.TaskId = taskId; |
| | | |
| | | // æ·»å 任塿§è¡è¯¦æ
|
| | | bool detailAdded = await _taskExecuteDetailRepository.AddDetailAsync( |
| | | task, |
| | | false, |
| | | TaskDescription.GetTaskUpdateDescription(input.PalletCode, input.Position, toAddress, TaskInStatusEnum.InNew.GetIntegralRuleTypeEnumDesc()) |
| | | ); |
| | | |
| | | if (!detailAdded) |
| | | { |
| | | return content.Error("æ·»å 任塿§è¡è¯¦æ
失败"); |
| | | } |
| | | |
| | | // å建WMSä»»å¡ |
| | | var taskDTO = new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.Roadway, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | }; |
| | | |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è¿éå¯ä»¥æ·»å æ¥å¿è®°å½ |
| | | return content.Error($"åå»ºä»»å¡æ¶åçé误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | // è·åå··éæç«å° |
| | | public async Task<string> GetRoadWayAsync(RequestTaskDto input, List<string> process) |
| | | { |
| | | var minGroup = _locationRepository.QueryData(x => process.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free) |
| | | .GroupBy(x => x.RoadwayNo) |
| | | .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»çå
ç´ æ°éæåº |
| | | .First(); // ååºæ°éæå¤çç» |
| | | |
| | | string minRoadwayNo = minGroup.Key; // æ°éæå¤çç»çKey |
| | | |
| | | return minRoadwayNo; |
| | | } |
| | | |
| | | // è·åæçåå
æ ¼ç¶æ |
| | | private async Task<WebResponseContent> GetTrayCellStatusAsync(TrayCellsStatusDto trayCells) |
| | | { |
| | | // è°ç¨_cellStateService.GetTrayCellStatusAsyncæ¹æ³ï¼è·åæçåå
æ ¼ç¶æ |
| | | return await _cellStateService.GetTrayCellStatusAsync(trayCells); |
| | | } |
| | | |
| | | // è·åç»çä¿¡æ¯ |
| | | private async Task<DtBoxingInfo> CreateBoxingInfo(ResultTrayCellsStatus result, string palletCode) |
| | | { |
| | | return new DtBoxingInfo |
| | | { |
| | | PalletCode = palletCode, |
| | | IsFull = true, |
| | | BoxingInfoDetails = result.SerialNos.Select(serialNoObj => new DtBoxingInfoDetail |
| | | { |
| | | SerialNumber = serialNoObj.SerialNo, |
| | | OrderNo = serialNoObj.PositionNo.ToString(), |
| | | Status = serialNoObj.SerialNoStatus, |
| | | MaterielCode = result.BindCode, |
| | | Remark = result.TrayBarcodePropertys.ToJsonString(), |
| | | }).ToList() |
| | | }; |
| | | } |
| | | |
| | | // è·åå·¥èºç³è¯· |
| | | private async Task<ProcessApplyDto> GetProcessApplyAsync(ResultTrayCellsStatus content) |
| | | { |
| | | // å建ä¸ä¸ªProcessApplyDto对象ï¼å¹¶èµå¼ |
| | | return new ProcessApplyDto() |
| | | { |
| | | EquipmentCode = "ECH001-B", |
| | | Software = "WMS", |
| | | //WipOrderNo = result.BindCode, |
| | | SerialNos = content.SerialNos.Select(item => new SerialNos |
| | | { |
| | | SerialNo = item.SerialNo |
| | | }).ToList() |
| | | }; |
| | | } |
| | | |
| | | // è·åå·¥èºååº |
| | | private async Task<List<Dt_EquipmentProcess>> GetProcessResponseAsync(ProcessApplyDto process, string position) |
| | | { |
| | | // 妿process为nullï¼åè¿ånull |
| | | if (process == null) return null; |
| | | |
| | | // è°ç¨_processApplyService.GetProcessApplyAsyncæ¹æ³ï¼è·åå·¥èºç³è¯· |
| | | WebResponseContent content = await _processApplyService.GetProcessApplyAsync(process); |
| | | // å¦æç¶æä¸ºfalseï¼åè¿ånull |
| | | if (!content.Status) return null; |
| | | |
| | | // å°content.Data转æ¢ä¸ºResultProcessApply对象 |
| | | var apply = JsonConvert.DeserializeObject<ResultProcessApply>(content.Data.ToString()); |
| | | // æ ¹æ®positionçå¼ï¼è¿åä¸åçDt_EquipmentProcesså表 |
| | | switch (position) |
| | | { |
| | | case "1088": |
| | | return SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>() |
| | | .Where(x => x.EquipmentType == "éå" && x.WipOrderNo == apply.WipOrderNo || x.ProductDesc == apply.ProductNo) |
| | | .ToList(); |
| | | case "1339": |
| | | case "1406": |
| | | return SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>() |
| | | .Where(x => x.EquipmentType == "éç½®" && x.WipOrderNo == apply.WipOrderNo || x.ProductDesc == apply.ProductNo) |
| | | .ToList(); |
| | | |
| | | default: |
| | | return new List<Dt_EquipmentProcess>(); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 请æ±åºåºï¼å®ç&空çï¼ |
| | | // è¯·æ±æçä»»å¡ |
| | | public async Task<WebResponseContent> RequestTrayOutTaskAsync(string position, int tag, string areaCode, List<string> roadways) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // æ ¹æ®æçç±»åæ¥è¯¢åºåä¿¡æ¯ |
| | | DtStockInfo stockInfo = tag == (int)TaskOutboundTypeEnum.Outbound |
| | | ? QueryStockInfoForRealTrayAsync(areaCode, roadways).Result |
| | | : QueryStockInfoForEmptyTrayAsync(areaCode, roadways).Result; |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | return content.Error("åºåä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | |
| | | // æ°å¢éå¤ä»»å¡æ ¡éª |
| | | var hasTask = BaseDal.QueryFirst(x => x.PalletCode == stockInfo.PalletCode); |
| | | if (hasTask != null) |
| | | { |
| | | WMSTaskDTO taskDTO1 = CreateTaskDTO(hasTask); |
| | | return content.OK("å·²åå¨ç©ºçåºåºä»»å¡", data: taskDTO1); |
| | | } |
| | | |
| | | // å建æ°ä»»å¡å®ä¾ |
| | | var task = CreateTask(stockInfo, position, tag); |
| | | var taskId = await BaseDal.AddDataAsync(task); |
| | | bool isResult = taskId > 0; |
| | | if (!isResult) |
| | | { |
| | | return content.Error("ä»»å¡å建失败"); |
| | | } |
| | | |
| | | // å建任å¡DTO |
| | | WMSTaskDTO taskDTO = CreateTaskDTO(task); |
| | | //if (tag == 1) |
| | | { |
| | | // æ´æ°åºåä½ç½®ç¶æä¸ºä¸å¯ç¨ |
| | | stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | await _locationRepository.UpdateDataAsync(stockInfo.LocationInfo); |
| | | } |
| | | |
| | | // è¿åæåååº |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½å¼å¸¸ä¿¡æ¯å¹¶æåº |
| | | _logFactory.GetLog("è¯·æ±æçä»»å¡").Error(true, ex); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | // æ¥è¯¢å®çåºåä¿¡æ¯ |
| | | private async Task<DtStockInfo> QueryStockInfoForRealTrayAsync(string areaCode, List<string> roadways) |
| | | { |
| | | // TODOæ¶é´æ ¹æ®MOMç³»ç»é
ç½®çåºåºæ¶é´æ¥è·å,ææ¶ä¸ç¥éMOMè¿åçæ¶é´æ¯ä»ä¹æä»¥è¿éæµè¯æ¶å卿¹ |
| | | var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>().Where(x => |
| | | x.AreaCode == areaCode && |
| | | Convert.ToDateTime(x.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(x.SpecialParameterDuration)) < DateTime.Now) |
| | | .Includes(x => x.LocationInfo) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && roadways.Contains(x.LocationInfo.RoadwayNo)) |
| | | .Includes(x => x.StockInfoDetails) |
| | | .Where(x => x.StockInfoDetails.Any(detail => detail.Status == (int)StockStateEmun.å·²å
¥åº)) |
| | | .OrderBy(x => x.CreateDate) |
| | | .FirstAsync(); |
| | | return result; |
| | | } |
| | | |
| | | // æ¥è¯¢ç©ºçåºåä¿¡æ¯ |
| | | private async Task<DtStockInfo> QueryStockInfoForEmptyTrayAsync(string areaCode, List<string> roadways) |
| | | { |
| | | var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Includes(x => x.LocationInfo) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && roadways.Contains(x.LocationInfo.RoadwayNo)) |
| | | .Includes(x => x.StockInfoDetails) |
| | | .Where(x => x.StockInfoDetails.Any(detail => detail.Status == (int)StockStateEmun.å·²å
¥åº && detail.MaterielCode == "空æç")) |
| | | .OrderBy(x => x.CreateDate) |
| | | .FirstAsync(); |
| | | return result; |
| | | } |
| | | |
| | | // å建任å¡å®ä¾ |
| | | private Dt_Task CreateTask(DtStockInfo stockInfo, string position, int tag) |
| | | { |
| | | return new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = stockInfo.LocationInfo.RoadwayNo, |
| | | TargetAddress = position, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = position, |
| | | OrderNo = null, |
| | | PalletCode = stockInfo.PalletCode, |
| | | SourceAddress = stockInfo.LocationCode, |
| | | CurrentAddress = stockInfo.LocationCode, |
| | | TaskState = (int)TaskOutStatusEnum.OutNew, |
| | | TaskType = tag == (int)TaskOutboundTypeEnum.Outbound ? (int)TaskOutboundTypeEnum.Outbound : (int)TaskOutboundTypeEnum.OutTray, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | Creater = "System" // ä¿®æ£æ¼åé误 |
| | | }; |
| | | } |
| | | |
| | | // å建任å¡DTO |
| | | private WMSTaskDTO CreateTaskDTO(Dt_Task task) |
| | | { |
| | | return new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = 1, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | }; |
| | | } |
| | | #endregion |
| | | |
| | | #region æ´æ°ä»»å¡ç¶æ |
| | | // æ´æ°ä»»å¡ç¶æ |
| | | public async Task<WebResponseContent> UpdateTaskStatus(int taskNum, int taskState) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(x => x.TaskNum == taskNum); |
| | | if (task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | |
| | | if (taskState == (int)TaskOutStatusEnum.Line_OutFinish || taskState == (int)TaskOutStatusEnum.SC_OutFinish) |
| | | { |
| | | var taskHty = CreateHistoricalTask(task); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | var asb = await BaseDal.DeleteDataByIdAsync(task.TaskId); |
| | | var asbHty = await _task_HtyRepository.AddDataAsync(taskHty) > 0; |
| | | if (asb && asbHty) |
| | | content.OK(); |
| | | else |
| | | throw new Exception(); |
| | | }); |
| | | content.OK(); |
| | | } |
| | | else |
| | | { |
| | | task.TaskState = taskState; |
| | | var asb = await BaseDal.UpdateDataAsync(task); |
| | | if (asb) |
| | | content.OK(); |
| | | else |
| | | content.Error(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | #region åºåºè§£ç |
| | | // åºåºè§£çæ¥å£ |
| | | public async Task<WebResponseContent> OutUnblockInterface(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(x => x.TaskNum == taskNum); |
| | | if (task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | task.TaskState = (int)TaskOutStatusEnum.Line_OutFinish; |
| | | var taskHty = CreateHistoricalTask(task); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | #region å
é¨è°ç¨æ¹æ³ |
| | | |
| | | // å建ä¸ä¸ªæ°çä»»å¡ |
| | | public async Task<Dt_Task> Create(Dt_Task model) |
| | | { |
| | | return await BaseDal.Create(model); |
| | | } |
| | | |
| | | // æ¹éåå»ºä»»å¡ |
| | | public async Task<bool> Create(List<Dt_Task> models) |
| | | { |
| | | return await BaseDal.Create(models); |
| | | } |
| | | |
| | | // å é¤ä¸ä¸ªä»»å¡ |
| | | public async Task<bool> Delete(int id) |
| | | { |
| | | return await BaseDal.Delete(id); |
| | | } |
| | | |
| | | // æ¹éå é¤ä»»å¡ |
| | | public async Task<bool> Delete(List<int> ids) |
| | | { |
| | | return await BaseDal.Delete(ids); |
| | | } |
| | | |
| | | // éè¿IDè·åä»»å¡ |
| | | public async Task<Dt_Task> GetById(int id) |
| | | { |
| | | return await BaseDal.GetById(id); |
| | | } |
| | | |
| | | // è·åææä»»å¡å表 |
| | | public async Task<List<Dt_Task>> GetList() |
| | | { |
| | | return await BaseDal.GetList(); |
| | | } |
| | | |
| | | // æ ¹æ®åºåºè®¢åIDè·åä»»å¡å表 |
| | | public async Task<List<Dt_Task>> GetListByOutOrder(int outOrderId) |
| | | { |
| | | return await BaseDal.GetListByOutOrder(outOrderId); |
| | | } |
| | | |
| | | // æ ¹æ®åºåºè®¢åIDåç¶æè·åä»»å¡å表 |
| | | public async Task<List<Dt_Task>> GetListByOutOrderAndStatus(int outOrderId, int status) |
| | | { |
| | | return await BaseDal.GetListByOutOrderAndStatus(outOrderId, status); |
| | | } |
| | | |
| | | // æ ¹æ®ç¶æè·åä»»å¡å表 |
| | | public async Task<List<Dt_Task>> GetListByStatus(int status) |
| | | { |
| | | return await BaseDal.GetListByStatus(status); |
| | | } |
| | | |
| | | // æ´æ°ä¸ä¸ªä»»å¡ |
| | | public async Task<bool> Update(Dt_Task model) |
| | | { |
| | | return await BaseDal.UpdateDataAsync(model); |
| | | } |
| | | |
| | | // æ¹éæ´æ°ä»»å¡ |
| | | public async Task<bool> Update(List<Dt_Task> models) |
| | | { |
| | | return await BaseDal.UpdateDataAsync(models); |
| | | } |
| | | |
| | | // æ£æ¥ä»»å¡æ¯å¦åå¨ |
| | | public bool IsExist(string palletCode) |
| | | { |
| | | return Db.Queryable<Dt_Task>().Any(x => x.PalletCode == palletCode); |
| | | } |
| | | |
| | | // æ ¹æ®è´§ä½IDè·åä»»å¡ |
| | | public async Task<Dt_Task> GetByLocation(string locationID) |
| | | { |
| | | return await Db.Queryable<Dt_Task>().Where(x => x.SourceAddress == locationID).FirstAsync(); |
| | | } |
| | | |
| | | // æ ¹æ®ä»»å¡å·è·åä»»å¡ |
| | | public async Task<Dt_Task> GetByTaskNum(int taskNum) |
| | | { |
| | | return await Db.Queryable<Dt_Task>().Where(x => x.TaskNum == taskNum).FirstAsync(); |
| | | } |
| | | #endregion |
| | | } |
| | | } |