| | |
| | | using Mapster; |
| | | using AngleSharp.Dom; |
| | | using log4net.Core; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; |
| | | using NewLife; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using OfficeOpenXml.Table.PivotTable; |
| | | using SixLabors.Fonts.Tables.AdvancedTypographic; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Security.Policy; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Location; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IOrderRepository; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEA_Model.Models.ERP; |
| | | using WIDESEA_Model.Models.Order; |
| | | using WIDESEA_OrderRepository; |
| | | using WIDESEA_StorageTaskRepository; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | |
| | | namespace WIDESEA_StorageTaskServices; |
| | | |
| | |
| | | private readonly IDt_AreaInfoRepository _areaInfoRepository; //åºå |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly ISimpleCacheService _simpleCacheService; |
| | | private readonly IDt_OrderOutDetailsRepository _orderOutDetailsRepository; |
| | | |
| | | public Dt_TaskService(IDt_TaskRepository BaseDal, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | |
| | | IStockInfoDetailRepository stockInfoDetailRepository, |
| | | IDt_StationManagerRepository stationManagerRepository, |
| | | ISys_ConfigService configService, |
| | | ISimpleCacheService simpleCacheService) : base(BaseDal) |
| | | IDt_OrderOutDetailsRepository orderOutDetailsRepository) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockInfoRepository = stockInfoRepository; |
| | |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _configService = configService; |
| | | _simpleCacheService = simpleCacheService; |
| | | _orderOutDetailsRepository = orderOutDetailsRepository; |
| | | } |
| | | |
| | | #region å¤é¨æ¥å£æ¹æ³ |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var locationStart = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.SourceAddress); |
| | | var locationEnd = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress); |
| | | |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | stock.ModifyDate = DateTime.Now; |
| | | stock.LocationCode = task.TargetAddress; |
| | | var result1 = UpdateLocationStatus(locationStart, LocationEnum.Free, task.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | var result2 = UpdateLocationStatus(locationEnd, LocationEnum.InStock, task.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); |
| | | var orderDetails = _orderOutDetailsRepository.QueryData(x => x.PalletCode == task.PalletCode); |
| | | List<Dt_OrderOutDetails_Hty> orderdetailshtys = new List<Dt_OrderOutDetails_Hty>(); |
| | | |
| | | orderDetails.ForEach(item => |
| | | { |
| | | orderdetailshtys.Add(item.Adapt<Dt_OrderOutDetails_Hty>()); |
| | | }); |
| | | |
| | | var allocateOrderdetail = orderDetails.Where(x => true).ToList(); |
| | | |
| | | //await ERPAllocateOut(stock); |
| | | |
| | | //è°æ¨åºåº |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.OutAllocate) |
| | | { |
| | | if (orderDetails.Count > 0) |
| | | await ERPAllocate(orderDetails.Where(x => x.OrderType == (int)OrderTypeEmun.è°æ¨åºåºå).ToList()); |
| | | } |
| | | //å
¶ä»åºåº |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.OutOther) |
| | | { |
| | | if (orderDetails.Count > 0) |
| | | { |
| | | await ERPMixedSend(orderDetails.Where(x => x.OrderType == (int)OrderTypeEmun.å
¶ä»åºåºå).ToList()); |
| | | } |
| | | } |
| | | //çäº§é¢æåºåº |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.MaterialRequisition) |
| | | { |
| | | if (orderDetails.Count > 0) |
| | | { |
| | | content = await ERPProduction(orderDetails.Where(x => x.OrderType == (int)OrderTypeEmun.çäº§é¢æå).ToList()); |
| | | } |
| | | } |
| | | List<DtBoxingInfo> boxingInfos = new List<DtBoxingInfo>(); |
| | | foreach (var item in allocateOrderdetail) |
| | | { |
| | | var boxingInfo = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == item.PalletCode); |
| | | if (boxingInfo == null) |
| | | { |
| | | continue; |
| | | } |
| | | var boxingdetail = boxingInfo.BoxingInfoDetails.Where(x => x.MaterielCode == item.MaterielCode).ToList(); |
| | | if (boxingdetail.Count() > 0) |
| | | { |
| | | foreach (var detail in boxingdetail) |
| | | { |
| | | //detail.Quantity = detail.Quantity - item.OutboundQuantity; |
| | | detail.Warehouse = "WMSåºåºç¼ååº"; |
| | | detail.WareHouseId = "205"; |
| | | //if (detail.Quantity <= 0) |
| | | //{ |
| | | // boxingInfo.BoxingInfoDetails.Remove(detail); |
| | | //} |
| | | } |
| | | } |
| | | boxingInfos.Add(boxingInfo); |
| | | } |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await DeleteStockInfoAsync(stock.Id); |
| | | _boxingInfoRepository.UpdateDataNav(boxingInfos); |
| | | await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); |
| | | await AddStockInfoHtyAsync(stockInfo_Hty); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result1.Item1); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result2.Item1); |
| | | await _locationRepository.UpdateDataAsync(result1.Item2); |
| | | await _locationRepository.UpdateDataAsync(result2.Item2); |
| | | await _orderOutDetailsRepository.DeleteDataAsync(orderDetails); |
| | | await SqlSugarHelper.DbWMS.Insertable(orderdetailshtys).ExecuteCommandAsync(); |
| | | |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | content.OK("åºåºå®æ"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | task.ErrorMessage = ex.Message; |
| | | await BaseDal.UpdateDataAsync(task); |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | #endregion åºåºä»»å¡å®æ |
| | | |
| | | #region ç§»åºä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// ç§»åºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="saveModel">任塿°æ®åé</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> CompleteTransferTaskAsync(Dt_Task task, DtStockInfo stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var locationStart = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.SourceAddress); |
| | | var locationEnd = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress); |
| | | |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | |
| | | stock.ModifyDate = DateTime.Now; |
| | | stock.LocationCode = task.TargetAddress; |
| | | var result = UpdateLocationStatus(locationEnd, LocationEnum.InStock, task.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticRelocation); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1); |
| | | await _locationRepository.UpdateDataAsync(result.Item2); |
| | | _stockInfoRepository.UpdateData(stock); |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | content.OK("ç§»åºå®æ"); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | Console.WriteLine(err.Message.ToString()); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | #endregion ç§»åºä»»å¡å®æ |
| | | |
| | | #region å
¥åºä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// 宿å
¥åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="task">任塿°æ®åé</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var boxinfo = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode); |
| | | var locationStart = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.SourceAddress); |
| | | var locationEnd = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress); |
| | | |
| | | if (boxinfo == null) |
| | | { |
| | | return content.Error("æªæ¾å°ç»çæ°æ®"); |
| | | } |
| | | |
| | | var stock = CreateStock(boxinfo, task); |
| | | |
| | | task.TaskState = (int)TaskInStatusEnum.InFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | |
| | | var result1 = UpdateLocationStatus(task.SourceAddress, LocationEnum.Free, task.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticInbound); |
| | | var result2 = UpdateLocationStatus(task.TargetAddress, LocationEnum.InStock, task.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticInbound); |
| | | |
| | | await ERPAllocate(stock); |
| | | |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await _stockInfoRepository.AddDataNavAsync(stock); |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result2.Item1); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result1.Item1); |
| | | await _locationRepository.UpdateDataAsync(result2.Item2); |
| | | await _locationRepository.UpdateDataAsync(result1.Item2); |
| | | }); |
| | | content.OK("å
¥åºå®æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | task.ErrorMessage = ex.Message; |
| | | await BaseDal.UpdateDataAsync(task); |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public DtStockInfo CreateStock(DtBoxingInfo boxingInfo,Dt_Task task) |
| | | { |
| | | var boxDetail = boxingInfo.BoxingInfoDetails.Adapt<List<DtStockInfoDetail>>(); |
| | | boxDetail.ForEach(x => { x.Status = (int)StockStateEmun.å·²å
¥åº; }); |
| | | return new DtStockInfo() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | LocationCode = task.TargetAddress, |
| | | CreateDate = DateTime.Now, |
| | | Creater = "system", |
| | | IsFullExit = boxingInfo.IsFullExit, |
| | | StockInfoDetails = boxDetail, |
| | | StockStatus = (int)StockStateEmun.å·²å
¥åº |
| | | }; |
| | | } |
| | | #endregion å
¥åºä»»å¡å®æ |
| | | |
| | | #region AGVæ¬è¿ä»»å¡å®æ |
| | | public async Task<WebResponseContent> CompleteCarryTaskAsync(Dt_Task task,DtStockInfo stockInfo) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.SourceAddress); |
| | | var Targetlocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress); |
| | | |
| | | //UpdateLocationStatus(Sourcelocation, LocationEnum.Free); |
| | | //UpdateLocationStatus(Targetlocation, LocationEnum.InStock); |
| | | |
| | | task.TaskState = (int)TaskAGVCarryStatusEnum.CarryFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region AGV跨楼å±ä»»å¡å®æ |
| | | public async Task<WebResponseContent> CompleteAcrossFloorTaskAsync(Dt_Task task, DtStockInfo stockInfo) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// å®æä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡ç¼å·</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | 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); |
| | | |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | return await CompleteOutboundTaskAsync(task, stock); |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | return await CompleteInboundTaskAsync(task); |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) |
| | | { |
| | | return await CompleteTransferTaskAsync(task, stock); |
| | | } |
| | | else |
| | | { |
| | | return content.Error("æªæ¾å°ä»»å¡ç±»å"); |
| | | } |
| | | } |
| | | |
| | | #endregion ä»»å¡å®æ |
| | | |
| | | #region åæ¶ä»»å¡ |
| | | public WebResponseContent TaskCancel(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) |
| | | { |
| | | return content = WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡ä¿¡æ¯"); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCancel"); |
| | | if (methodInfo != null) |
| | | { |
| | | WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task }); |
| | | if (responseContent != null) |
| | | { |
| | | if (responseContent != null) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | return content = WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡ç±»å对åºä¸å¡å¤çé»è¾"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 请æ±ä»»å¡å
¥åº |
| | | |
| | | public async Task<WebResponseContent> RequestInboundTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var boxingInfo = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == taskDto.PalletCode && x.StockStatus == (int)StockStateEmun.ç»çæå); |
| | | |
| | | if (boxingInfo == null) |
| | | { |
| | | return content.Error("æçä¿¡æ¯ä¸åå¨ï¼è¯·ç¡®è®¤æçå·²ç»çæå"); |
| | | } |
| | | |
| | | foreach (var item in boxingInfo.BoxingInfoDetails) |
| | | { |
| | | var ERPStock = SqlSugarHelper.DBERPtext.Queryable<ç¨å峿¶åºå_ST>().Where(x => x.åå¨å°ç¹åç§° == item.Warehouse && x.æå· == item.MaterielCode && x.åå == item.MaterielName && x.åºåæ°é >= item.Quantity).ToList().FirstOrDefault(); |
| | | if (ERPStock == null) |
| | | { |
| | | return content.Error($"ç»çæ°æ®æªå¨ERPåºåæ°æ®ä¸ï¼è¯·äººå·¥ç¡®è®¤æ°æ®æ¯å¦æ£ç¡®"); |
| | | } |
| | | } |
| | | |
| | | var StartAddress = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | if (StartAddress == null) |
| | | { |
| | | return content.Error("èµ·ç¹åºä½æªæ¾å°"); |
| | | } |
| | | if (!LocationIsOutBound(StartAddress)) |
| | | { |
| | | return content.Error($"èµ·ç¹åºä½{StartAddress.LocationCode}æ¬è¿è·¯å¾è¢«å ç¨ï¼è¯·äººå·¥ç¡®è®¤åä¸åä»»å¡"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task(); |
| | | DtLocationInfo Endlocation= new DtLocationInfo(); |
| | | if (taskDto.AreaId != 0) |
| | | { |
| | | switch (taskDto.AreaId) |
| | | { |
| | | case 1: |
| | | Endlocation = await GetEmptyLocation("SC1"); |
| | | taskNew = InboundStakerArea(taskDto, StartAddress, Endlocation); |
| | | break; |
| | | case 2: |
| | | case 3: |
| | | case 4: |
| | | case 5: |
| | | case 6: |
| | | Endlocation = await GetAGVEmptyCacheLocation(taskDto.AreaId, StartAddress); |
| | | taskNew = InboundAGVCacheArea(taskDto, StartAddress, Endlocation); |
| | | break; |
| | | default: |
| | | return content.Error("è¯·éæ©æ£ç¡®çåºåä¿¡æ¯"); |
| | | } |
| | | } |
| | | else if (taskDto.TargetAddress != null) |
| | | { |
| | | Endlocation = _locationRepository.QueryFirst(x => x.LocationCode == taskDto.TargetAddress); |
| | | if (Endlocation != null && Endlocation.LocationStatus == (int)LocationEnum.Free && Endlocation.EnalbeStatus == 1) |
| | | { |
| | | switch (Endlocation.AreaId) |
| | | { |
| | | case 1: |
| | | taskNew = InboundStakerArea(taskDto, StartAddress, Endlocation); |
| | | break; |
| | | case 2: |
| | | case 3: |
| | | case 4: |
| | | case 5: |
| | | case 6: |
| | | taskNew = InboundAGVCacheArea(taskDto, StartAddress, Endlocation); |
| | | break; |
| | | default: |
| | | return content.Error("è´§ä½åºåæªæ¾å°"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return content.OK("ç®æ åºä½ä¸å¯ç¨"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return content.Error("è¯·éæ©å
¥åºåºåæç»ç¹å°å"); |
| | | } |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var result1 = UpdateLocationStatus(StartAddress, LocationEnum.InStockDisable, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticInbound); |
| | | var result2 = UpdateLocationStatus(Endlocation, LocationEnum.Lock, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticInbound); |
| | | |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result1.Item1); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result2.Item1); |
| | | await _locationRepository.UpdateDataAsync(result1.Item2); |
| | | await _locationRepository.UpdateDataAsync(result2.Item2); |
| | | BaseDal.AddData(taskNew); |
| | | }); |
| | | return content = await SendWCSTask(taskDTO); |
| | | //return content.OK("æå"); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | return content.Error(err.Message); |
| | | } |
| | | } |
| | | |
| | | public Dt_Task InboundStakerArea(RequestTaskDto taskDto, DtLocationInfo StartAddress,DtLocationInfo EndLocation) |
| | | { |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.Roadway == "SC1"); |
| | | if (EndLocation == null) |
| | | { |
| | | throw new Exception("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | return new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "SC1", |
| | | TargetAddress = EndLocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = station.stationChildCode, |
| | | OrderNo = null, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = (int)TaskInboundTypeEnum.Inbound, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = "1F", |
| | | }; |
| | | } |
| | | |
| | | public Dt_Task InboundAGVCacheArea(RequestTaskDto taskDto, DtLocationInfo StartAddress, DtLocationInfo location) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | if (location == null) |
| | | { |
| | | throw new Exception("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task(); |
| | | if (StartAddress.Floor != location.Floor) |
| | | { |
| | | taskNew = RequestAcrossFloorTask(StartAddress, location, (int)TaskInboundTypeEnum.Inbound, taskDto); |
| | | } |
| | | else |
| | | { |
| | | taskNew = RequestAGVCarryTask(StartAddress, location, (int)TaskInboundTypeEnum.Inbound, taskDto); |
| | | } |
| | | return taskNew; |
| | | |
| | | } |
| | | #endregion 请æ±ä»»å¡å
¥åº |
| | | |
| | | #region æ´æ°ä»»å¡ç¶æ |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡è´§ä½ |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | 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("æªæ¾å°ä»»å¡"); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public async Task<WebResponseContent> RequestLocationAsync(RequestTaskDto input) |
| | | { |
| | | await _semaphoreUpdate.WaitAsync(); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == input.PalletCode); |
| | | if (task == null) |
| | | { |
| | | return content.Error("ä»»å¡å¯¹è±¡ä¸ºç©º"); |
| | | } |
| | | |
| | | task.TaskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | var location = await GetEmptyLocation(task.Roadway); |
| | | if (location == null) |
| | | { |
| | | return content.Error("æ æ³è·åè´§ä½ä¿¡æ¯"); |
| | | } |
| | | int beforeStatus = location.LocationStatus; |
| | | |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | task.CurrentAddress = input.Position; |
| | | task.TargetAddress = location.LocationCode; |
| | | task.NextAddress = location.LocationCode; |
| | | task.TaskState = (int)TaskInStatusEnum.Line_InFinish; |
| | | // å¼å§äºå¡ |
| | | var isResult = await UpdateTaskAsync(task, location, beforeStatus); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ´æ°ä»»å¡å¤±è´¥"); |
| | | } |
| | | return content.OK(data: task); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | finally { _semaphoreUpdate.Release(); } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±åºåº |
| | | /// <summary> |
| | | /// æå¨åºåºè³ç¼ååºå |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> OutBoundTaskAsync(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | DtStockInfo stcok = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == palletCode); |
| | | if (stcok == null) |
| | | { |
| | | return content.Error("æçä¿¡æ¯ä¸åå¨ï¼è¯·ç¡®è®¤æçå·²å
¥åºæå"); |
| | | } |
| | | |
| | | if (stcok.LocationInfo.LocationStatus != (int)LocationEnum.InStock) |
| | | { |
| | | return content.Error("请确认åºåè´§ä½ç¶ææ¯å¦ä¸ºæè´§"); |
| | | } |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); |
| | | if (task != null) |
| | | { |
| | | return content.Error("该æçå·²åå¨ä»»å¡"); |
| | | } |
| | | |
| | | var location = await _locationRepository.QueryFirstAsync(x => x.LocationCode == stcok.LocationCode); |
| | | if (location.AreaId == 2) |
| | | { |
| | | return content.Error("该æçåºåå·²å¨åºåºç¼ååº"); |
| | | } |
| | | |
| | | Dt_Task taskNew = await RequestOutboundTaskAsync(new RequestTaskDto { PalletCode = palletCode, AreaId = 2, Position = stcok.LocationCode, TaskType = (int)TaskOutboundTypeEnum.Outbound }); |
| | | |
| | | var taskDto = CreateListTaskDTO(taskNew); |
| | | var result = GetlcoationState(taskNew, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | BaseDal.AddData(taskNew); |
| | | _stockInfoRepository.UpdateData(stcok); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1); |
| | | await _locationRepository.UpdateDataAsync(result.Item2); |
| | | }); |
| | | return content = await SendWCSTask(taskDto); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | public async Task<WebResponseContent> OtherOutBoundTaskAsync(List<DtStockInfoDetail> details) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.Id == details[0].StockId); |
| | | if (stock == null) |
| | | { |
| | | return content.Error("æªæ¾å°åºå表头信æ¯"); |
| | | } |
| | | if (stock.LocationInfo.LocationStatus != (int)LocationEnum.InStock) |
| | | { |
| | | return content.Error("请确认åºåè´§ä½ç¶ææ¯å¦ä¸ºæè´§"); |
| | | } |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == stock.PalletCode); |
| | | if (task != null) |
| | | { |
| | | return content.Error("该æçå·²åå¨ä»»å¡"); |
| | | } |
| | | if (stock.LocationInfo.AreaId == 2) |
| | | { |
| | | return content.Error("该æçåºåå·²å¨åºåºç¼ååº"); |
| | | } |
| | | |
| | | Dt_Task taskNew = await RequestOutboundTaskAsync(new RequestTaskDto { PalletCode = stock.PalletCode, AreaId = 2, Position = stock.LocationCode, TaskType = (int)TaskOutboundTypeEnum.OutOther }); |
| | | |
| | | List<Dt_OrderOutDetails> outDetails = new List<Dt_OrderOutDetails>(); |
| | | details.Where(x => x.OutboundQuantity > 0).ForEach(x => |
| | | { |
| | | if (x.Quantity < x.OutboundQuantity) |
| | | { |
| | | throw new Exception($"{x.MaterielName}{x.MaterielCode}åºåºæ°éä¸å¯å¤§äºåºåæ°é"); |
| | | } |
| | | outDetails.Add(new Dt_OrderOutDetails() |
| | | { |
| | | OrderNo = "", |
| | | PalletCode = stock.PalletCode, |
| | | OrderType = (int)OrderTypeEmun.å
¶ä»åºåºå, |
| | | ERPOrderId = "", |
| | | MaterielCode = x.MaterielCode, |
| | | MaterielName = x.MaterielName, |
| | | AllocateWarehouse = "", |
| | | Warehouse = "æºè½ç«åº", |
| | | WareHouseId = "107", |
| | | AllocateWarehouseId = "", |
| | | OutboundQuantity = x.OutboundQuantity, |
| | | }); |
| | | }); |
| | | stock.StockInfoDetails = details; |
| | | |
| | | var taskDto = CreateListTaskDTO(taskNew); |
| | | var result = GetlcoationState(taskNew, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await BaseDal.AddDataAsync(taskNew); |
| | | await _stockInfoRepository.UpdateDataNavAsync(stock); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1); |
| | | await _locationRepository.UpdateDataAsync(result.Item2); |
| | | await _orderOutDetailsRepository.AddDataAsync(outDetails); |
| | | }); |
| | | return content = await SendWCSTask(taskDto); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¨è°æ¨ |
| | | /// </summary> |
| | | /// <param name="details"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> HandAllocateOutBoundTaskAsync(List<DtStockInfoDetail> details) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.Id == details[0].StockId); |
| | | if (stock == null) |
| | | { |
| | | return content.Error("æªæ¾å°åºå表头信æ¯"); |
| | | } |
| | | if (stock.LocationInfo.LocationStatus != (int)LocationEnum.InStock) |
| | | { |
| | | return content.Error("请确认åºåè´§ä½ç¶ææ¯å¦ä¸ºæè´§"); |
| | | } |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == stock.PalletCode); |
| | | if (task != null) |
| | | { |
| | | return content.Error("该æçå·²åå¨ä»»å¡"); |
| | | } |
| | | if (stock.LocationInfo.AreaId == 2) |
| | | { |
| | | return content.Error("该æçåºåå·²å¨åºåºç¼ååº"); |
| | | } |
| | | |
| | | Dt_Task taskNew = await RequestOutboundTaskAsync(new RequestTaskDto { PalletCode = stock.PalletCode, AreaId = 2, Position = stock.LocationCode, TaskType = (int)TaskOutboundTypeEnum.OutAllocate }); |
| | | |
| | | List<Dt_OrderOutDetails> outDetails = new List<Dt_OrderOutDetails>(); |
| | | details.Where(x => x.OutboundQuantity > 0).ForEach(x => |
| | | { |
| | | var areaName = _areaInfoRepository.QueryFirst(y => y.AreaID == Convert.ToInt32(x.Remark)); |
| | | if (areaName == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°è°æ¨ä»åº{x.Remark}æ°æ®"); |
| | | } |
| | | if (x.Quantity < x.OutboundQuantity) |
| | | { |
| | | throw new Exception($"{x.MaterielName}{x.MaterielCode}åºåºæ°éä¸å¯å¤§äºåºåæ°é"); |
| | | } |
| | | outDetails.Add(new Dt_OrderOutDetails() |
| | | { |
| | | OrderNo = "", |
| | | PalletCode = stock.PalletCode, |
| | | OrderType = (int)OrderTypeEmun.è°æ¨åºåºå, |
| | | ERPOrderId = "", |
| | | MaterielCode = x.MaterielCode, |
| | | MaterielName = x.MaterielName, |
| | | AllocateWarehouse = areaName.AreaName, |
| | | Warehouse = "æºè½ç«åº", |
| | | WareHouseId = "107", |
| | | AllocateWarehouseId = areaName.AreaCode , |
| | | OutboundQuantity = x.OutboundQuantity, |
| | | }); |
| | | }); |
| | | |
| | | stock.StockInfoDetails = details; |
| | | |
| | | var taskDto = CreateListTaskDTO(taskNew); |
| | | var result = GetlcoationState(taskNew, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | await BaseDal.AddDataAsync(taskNew); |
| | | await _stockInfoRepository.UpdateDataNavAsync(stock); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1); |
| | | await _locationRepository.UpdateDataAsync(result.Item2); |
| | | await _orderOutDetailsRepository.AddDataAsync(outDetails); |
| | | }); |
| | | return content = await SendWCSTask(taskDto); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(); |
| | | } |
| | | } |
| | | |
| | | public (List<DtLocationStatusChangeRecord>,List<DtLocationInfo>) GetlcoationState(Dt_Task task,int StatusChangeTypeEnum) |
| | | { |
| | | List<DtLocationStatusChangeRecord> locationStatusChangeRecords = new List<DtLocationStatusChangeRecord>(); |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | var result1 = UpdateLocationStatus(task.SourceAddress, LocationEnum.InStockDisable, task.TaskNum.Value, StatusChangeTypeEnum); |
| | | var result2 = UpdateLocationStatus(task.TargetAddress, LocationEnum.Lock, task.TaskNum.Value, StatusChangeTypeEnum); |
| | | locationStatusChangeRecords.AddRange(result1.Item1); |
| | | locationStatusChangeRecords.AddRange(result2.Item1); |
| | | locations.AddRange(result1.Item2); |
| | | locations.AddRange(result2.Item2); |
| | | |
| | | return (locationStatusChangeRecords,locations); |
| | | } |
| | | |
| | | public (List<DtLocationStatusChangeRecord>, List<DtLocationInfo>) GetlcoationState(List<Dt_Task> tasks, int StatusChangeTypeEnum) |
| | | { |
| | | List<DtLocationStatusChangeRecord> locationStatusChangeRecords = new List<DtLocationStatusChangeRecord>(); |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | foreach (var item in tasks) |
| | | { |
| | | var result1 = UpdateLocationStatus(item.SourceAddress, LocationEnum.InStockDisable, item.TaskNum.Value, StatusChangeTypeEnum); |
| | | var result2 = UpdateLocationStatus(item.TargetAddress, LocationEnum.Lock, item.TaskNum.Value, StatusChangeTypeEnum); |
| | | locationStatusChangeRecords.AddRange(result1.Item1); |
| | | locationStatusChangeRecords.AddRange(result2.Item1); |
| | | locations.AddRange(result1.Item2); |
| | | locations.AddRange(result2.Item2); |
| | | } |
| | | return (locationStatusChangeRecords, locations); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 请æ±åºåºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskDto"></param> |
| | | /// <returns></returns> |
| | | public async Task<Dt_Task> RequestOutboundTaskAsync(RequestTaskDto taskDto) |
| | | { |
| | | DtStockInfo stcok = await _stockInfoRepository.QueryFirstAsync(x => x.PalletCode == taskDto.PalletCode); |
| | | if (stcok == null) |
| | | { |
| | | throw new Exception("æçä¿¡æ¯ä¸åå¨ï¼è¯·ç¡®è®¤æçå·²å
¥åºæå"); |
| | | } |
| | | |
| | | var StartAddress = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | if (StartAddress == null) |
| | | { |
| | | throw new Exception("èµ·ç¹åºä½æªæ¾å°"); |
| | | } |
| | | if (!LocationIsOutBound(StartAddress)) |
| | | { |
| | | throw new Exception($"èµ·ç¹åºä½{StartAddress.LocationCode}åºåºè·¯å¾è¢«å ç¨ï¼è¯·äººå·¥ç¡®è®¤åä¸åä»»å¡"); |
| | | } |
| | | DtLocationInfo location = null; |
| | | if (taskDto.AreaId != 0) |
| | | { |
| | | if (taskDto.AreaId == 1) |
| | | { |
| | | location = await GetEmptyLocation("SC1"); |
| | | } |
| | | else |
| | | { |
| | | location = await GetAGVEmptyCacheLocation(taskDto.AreaId, StartAddress); |
| | | } |
| | | |
| | | } |
| | | else if (taskDto.TargetAddress != null) |
| | | { |
| | | location = _locationRepository.QueryFirst(x => x.LocationCode == taskDto.TargetAddress); |
| | | |
| | | if (location != null && location.LocationStatus != (int)LocationEnum.Free && location.EnalbeStatus == 1) |
| | | { |
| | | throw new Exception("ç®æ åºä½ä¸å¯ç¨"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("è¯·éæ©å
¥åºåºåæç»ç¹å°å"); |
| | | } |
| | | switch (StartAddress.AreaId) |
| | | { |
| | | case 1: |
| | | return OutboundStakerArea(taskDto, StartAddress, location); |
| | | case 2: |
| | | case 3: |
| | | case 4: |
| | | case 5: |
| | | case 6: |
| | | return OutboundAGVCacheArea(taskDto, StartAddress, location); |
| | | default: |
| | | throw new Exception("è¯·éæ©æ£ç¡®çåºåä¿¡æ¯"); |
| | | } |
| | | } |
| | | |
| | | |
| | | public Dt_Task OutboundStakerArea(RequestTaskDto taskDto, DtLocationInfo StartAddress, DtLocationInfo location) |
| | | { |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.Roadway == "SC1"); |
| | | |
| | | if (location == null) |
| | | { |
| | | throw new Exception("ç»ç¹åºåæªæ¾å°ç©ºé²åºä½"); |
| | | } |
| | | |
| | | if (location.AreaId == 5 || location.AreaId == 6) |
| | | { |
| | | throw new Exception("å½ååºåä¸å¯åºåºï¼è¯·è系管çå"); |
| | | } |
| | | return new Dt_Task |
| | | { |
| | | Grade = Convert.ToInt32(StartAddress.Remark), |
| | | Roadway = "SC1", |
| | | TargetAddress = location.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = taskDto.MaterielCode, |
| | | NextAddress = station.stationChildCode, |
| | | OrderNo = taskDto.OrderNo, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = taskDto.Position, |
| | | CurrentAddress = taskDto.Position, |
| | | TaskState = (int)TaskOutStatusEnum.OutNew, |
| | | TaskType = taskDto.TaskType, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = "1F", |
| | | }; |
| | | } |
| | | |
| | | public Dt_Task OutboundAGVCacheArea(RequestTaskDto taskDto, DtLocationInfo StartAddress, DtLocationInfo location) |
| | | { |
| | | if (location == null) |
| | | { |
| | | throw new Exception("èµ·ç¹æªå®ä¹æç»ç¹åºåæªæ¾å°ç©ºé²åºä½"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task(); |
| | | if (StartAddress.Floor != location.Floor) |
| | | { |
| | | taskNew = RequestAcrossFloorTask(StartAddress, location, taskDto.TaskType, taskDto); |
| | | } |
| | | else |
| | | { |
| | | taskNew = RequestAGVCarryTask(StartAddress, location, taskDto.TaskType, taskDto); |
| | | } |
| | | return taskNew; |
| | | |
| | | } |
| | | #endregion 请æ±åºåºï¼å®ç&空çï¼ |
| | | |
| | | #region 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// <summary> |
| | | /// 请æ±è·¨æ¥¼å±2ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskDto"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> AcrossFloorTaskAsync(RequestAcrossFloorTaskDto taskDto) |
| | | { |
| | | WebResponseContent content=new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.TaskNum == Convert.ToInt32(taskDto.TaskNum) && x.PalletCode == taskDto.PalletCode); |
| | | if(task == null) |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | Dt_StationManager stationManager = new Dt_StationManager(); |
| | | if (task.Floor == "1F") |
| | | { |
| | | stationManager = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == "2F"); |
| | | } |
| | | else |
| | | { |
| | | stationManager = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == "1F"); |
| | | } |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "AGV", |
| | | TargetAddress = task.TargetAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = task.TargetAddress, |
| | | OrderNo = null, |
| | | PalletCode = task.PalletCode, |
| | | SourceAddress = task.SourceAddress, |
| | | CurrentAddress = stationManager.stationChildCode, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.SecondCarry, |
| | | TaskType = task.TaskType, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = stationManager.stationFloor, |
| | | }; |
| | | var taskDTO = CreateTaskDTO(taskNew); |
| | | task.TaskState = (int)TaskAcrossFloorStatusEnum.FirstCarryFinish; |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | BaseDal.AddData(taskNew); |
| | | }); |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±è·¨æ¥¼å±ä»»å¡ |
| | | public Dt_Task RequestAcrossFloorTask(DtLocationInfo StartAddress, DtLocationInfo EndAddress, int TaskType, RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == StartAddress.Floor); |
| | | return new Dt_Task |
| | | { |
| | | Grade = StartAddress.Column, |
| | | Roadway = "AGV", |
| | | TargetAddress = EndAddress.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = taskDto.MaterielCode, |
| | | NextAddress = next.stationChildCode, |
| | | OrderNo = taskDto.OrderNo, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = StartAddress.LocationCode, |
| | | CurrentAddress = StartAddress.LocationCode, |
| | | TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew, |
| | | TaskType = TaskType, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | Remark = StartAddress.AreaId.ToString(), |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = StartAddress.Floor, |
| | | }; |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 请æ±AGVæ¬è¿ä»»å¡ |
| | | public Dt_Task RequestAGVCarryTask(DtLocationInfo StartAddress, DtLocationInfo EndAddress, int TaskType, RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | return new Dt_Task |
| | | { |
| | | Grade = StartAddress.Column, |
| | | Roadway = "AGV", |
| | | TargetAddress = EndAddress.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = taskDto.MaterielCode, |
| | | NextAddress = EndAddress.LocationCode, |
| | | OrderNo = taskDto.OrderNo, |
| | | PalletCode = taskDto.PalletCode, |
| | | SourceAddress = StartAddress.LocationCode, |
| | | CurrentAddress = StartAddress.LocationCode, |
| | | TaskState = (int)TaskAGVCarryStatusEnum.CarryNew, |
| | | TaskType = TaskType, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | Remark = StartAddress.AreaId.ToString(), |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = StartAddress.Floor, |
| | | }; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 夿æ¯å¦éè¦ç§»åº |
| | | |
| | | /// <summary> |
| | | /// 夿å åæºåºåºæ¯å¦éè¦ç§»åº |
| | | /// </summary> |
| | | /// <param name="taskDto"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> StackerIsNeedRelocationAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.PalletCode == taskDto.PalletCode && x.TaskNum == taskDto.TaskNum); |
| | | if (task == null) |
| | | { |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | } |
| | | |
| | | var location = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | if (location == null || location.Depth != 2) |
| | | { |
| | | return content.OK(data: _mapper.Map<WMSTaskDTO>(task)); |
| | | } |
| | | |
| | | var locationLateral = _locationRepository.QueryFirst(x => x.RoadwayNo == location.RoadwayNo && x.Row == 1 && x.Layer == location.Layer && x.Column == location.Column); |
| | | if (locationLateral != null && (locationLateral.LocationStatus == (int)LocationEnum.FreeDisable || locationLateral.LocationStatus == (int)LocationEnum.Free) && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | return content.OK(data: _mapper.Map<WMSTaskDTO>(task)); |
| | | } |
| | | else if (locationLateral != null && locationLateral.LocationStatus == 1 && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | return content.Error($"䏿·±ä½å¼å¸¸é宿ä¸å¯åºåº"); |
| | | } |
| | | else if (locationLateral != null && locationLateral.LocationStatus == (int)LocationEnum.InStockDisable && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | var TargetAddress = await GetEmptyLocation("SC1"); |
| | | |
| | | if (TargetAddress == null) |
| | | { |
| | | return content.Error($"æªæ¾å°å¯åé
è´§ä½,请æ¥çæ¯å¦è¿æç©ºé²å¯ä½¿ç¨è´§ä½"); |
| | | } |
| | | |
| | | //todoæ¥è¯¢å
ä¾§åºåä¿¡æ¯ |
| | | var stock = await _stockInfoRepository.QueryFirstAsync(x => x.LocationCode == locationLateral.LocationCode); |
| | | |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = 1, |
| | | Roadway = "SC1", |
| | | TargetAddress = TargetAddress.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = TargetAddress.LocationCode, |
| | | OrderNo = null, |
| | | PalletCode = stock.PalletCode, |
| | | SourceAddress = locationLateral.LocationCode, |
| | | CurrentAddress = locationLateral.LocationCode, |
| | | TaskState = (int)TaskRelocationStatusEnum.RelocationNew, |
| | | TaskType = (int)TaskRelocationTypeEnum.Relocation, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | Floor = "1F", |
| | | }; |
| | | var taskDTO = CreateListTaskDTO(taskNew); |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, locationLateral, TargetAddress); |
| | | //UpdateLocationStatus(TargetAddress, LocationEnum.Lock); |
| | | UpdateLocationStatus(TargetAddress, LocationEnum.Lock, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticRelocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | else |
| | | { |
| | | return content.Error("è´§ä½å¼å¸¸é人工确认æå¯åºåº"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public async Task<WebResponseContent> AGVIsNeedRelocationAsync(RequestTaskDto taskDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.PalletCode == taskDto.PalletCode && x.TaskNum == taskDto.TaskNum); |
| | | if (task == null) |
| | | { |
| | | return content.Error("æªæ¾å°ä»»å¡"); |
| | | } |
| | | |
| | | var location = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position); |
| | | |
| | | if (location == null) |
| | | { |
| | | return content.Error("æªæ¾å°è´§ä½æè
该åºä½ä¸æ¯äºæ·±è´§ä½"); |
| | | } |
| | | List<DtLocationInfo> locationInfos = new List<DtLocationInfo>(); |
| | | switch (location.AreaId) |
| | | { |
| | | case 2: |
| | | locationInfos = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark && x.AreaId == location.AreaId); |
| | | break; |
| | | case 5: |
| | | case 6: |
| | | locationInfos = _locationRepository.QueryData(x => x.Row == location.Row && x.Column < location.Column && x.Remark == location.Remark && x.AreaId == location.AreaId); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | if (locationInfos.Count == 0) |
| | | { |
| | | return content.OK(data: new List<WMSTaskDTO> { _mapper.Map<WMSTaskDTO>(task) }); |
| | | } |
| | | |
| | | List<WMSTaskDTO> taskDTO = new List<WMSTaskDTO>(); |
| | | |
| | | foreach (var item in locationInfos) |
| | | { |
| | | if ((item.LocationStatus == 0 || item.LocationStatus == (int)LocationEnum.FreeDisable) && item.EnalbeStatus == 1) |
| | | { |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | DtLocationInfo Targetlocation = await GetAGVEmptyCacheLocation(item.AreaId, item); |
| | | |
| | | if (Targetlocation == null) |
| | | { |
| | | return content.Error("èµ·ç¹æªå®ä¹æç»ç¹åºåæªæ¾å°ç©ºé²åºä½"); |
| | | } |
| | | //todoæ¥è¯¢ç§»åºåºåä¿¡æ¯ |
| | | |
| | | Dt_Task taskNew = new Dt_Task |
| | | { |
| | | Grade = item.Column, |
| | | Roadway = "AGV", |
| | | TargetAddress = Targetlocation.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = Targetlocation.LocationCode, |
| | | OrderNo = null, |
| | | PalletCode = _random.Next(0, 10000).ToString(), |
| | | SourceAddress = item.LocationCode, |
| | | CurrentAddress = item.LocationCode, |
| | | TaskState = (int)TaskAGVCarryStatusEnum.CarryNew, |
| | | TaskType = (int)TaskRelocationTypeEnum.Relocation, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | AGVTaskNum = GenerateUniqueId(), |
| | | Floor = item.Floor, |
| | | Remark = item.AreaId.ToString(), |
| | | }; |
| | | taskDTO.Add(CreateTaskDTO(taskNew)); |
| | | |
| | | var isResult = await AddTaskAsync(taskNew, item, Targetlocation); |
| | | UpdateLocationStatus(Targetlocation, LocationEnum.Lock, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticRelocation); |
| | | if (!isResult) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error("æ°å¢ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | return content.OK(data: taskDTO); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region è·åAGVä»»å¡å· |
| | | |
| | | private static readonly Random _random = new Random(); |
| | | |
| | | public static string GenerateUniqueId() |
| | | { |
| | | // è·åå½å毫ç§çº§æ¶é´æ³ |
| | | long timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| | | |
| | | // çæ4ä½éæºæ°ï¼0000-9999ï¼ |
| | | int randomNumber = _random.Next(0, 10000); |
| | | string randomPart = randomNumber.ToString("D4"); // è¡¥é¶å°4ä½ |
| | | |
| | | return $"{timestamp}{randomPart}"; |
| | | } |
| | | #endregion |
| | | |
| | | #region è·åä»»å¡ä¿¡æ¯ |
| | | public WebResponseContent GetTaskInfo() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Expression<Func<Dt_Task, bool>> expression = x => true; |
| | | if (!App.User.IsSuperAdmin) |
| | | { |
| | | expression = x => x.Creater == App.User.UserName; |
| | | } |
| | | var task = BaseDal.Db.Queryable<Dt_Task>().OrderByDescending(x => x.CreateDate).Take(100).Select(x => new Dt_Task { TaskNum = x.TaskNum, PalletCode = x.PalletCode, TaskType = x.TaskType, SourceAddress = x.SourceAddress, TargetAddress = x.TargetAddress }).ToList(); |
| | | content = WebResponseContent.Instance.OK(data: task); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | #region è·å任塿°æ® |
| | | public async Task<WebResponseContent> GetTaskData() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryDataAsync(x => true); |
| | | var taskData = new List<TaskData> |
| | | { |
| | | new TaskData { Status = "已忶", Count = task.Count+50 }, |
| | | new TaskData { Status = "已宿", Count = 735 } |
| | | }; |
| | | |
| | | // æå»ºç¬¦åè¦æ±çæ ¼å¼ |
| | | var result = taskData.Select(item => new |
| | | { |
| | | value = item.Count, |
| | | name = item.Status, |
| | | itemStyle = new { color = item.Status == "已忶" ? "#FF0000" : "#00FF00" } |
| | | }).ToList(); |
| | | |
| | | return content.OK(data: result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | #region è°ç¨WCSæ¥å£ |
| | | private string GetWCSIPAddress(string baseIp, string name) |
| | | { |
| | | var configz = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wcsBasez = configz.Where(x => x.ConfigKey == baseIp).FirstOrDefault()?.ConfigValue; |
| | | var address = configz.Where(x => x.ConfigKey == name).FirstOrDefault()?.ConfigValue; |
| | | if (wcsBasez == null || address == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP æªé
ç½®"); |
| | | } |
| | | return wcsBasez + address; |
| | | } |
| | | |
| | | public async Task<WebResponseContent> SendWCSTask(List<WMSTaskDTO> taskDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var AgvSendTaskAddrss = GetWCSIPAddress(SysConfigConst.WCSIPAddress, SysConfigConst.ReceiveTask); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | var result = await HttpHelper.PostAsync(AgvSendTaskAddrss, taskDTO.ToJsonString()); |
| | | |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result.ToString()); |
| | | |
| | | return content; |
| | | } |
| | | #endregion |
| | | |
| | | #region ERPæ¥å£è°ç¨ |
| | | public string GetERPIPAddress(string baseIp, string name) |
| | | { |
| | | var configz = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wcsBasez = configz.Where(x => x.ConfigKey == baseIp).FirstOrDefault()?.ConfigValue; |
| | | var address = configz.Where(x => x.ConfigKey == name).FirstOrDefault()?.ConfigValue; |
| | | if (wcsBasez == null || address == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP æªé
ç½®"); |
| | | } |
| | | return wcsBasez + address; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çäº§é¢æ |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> ERPProduction(List<Dt_OrderOutDetails> orderOutDetails) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | MaterialRequisition materialRequisition = new MaterialRequisition |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "LL20", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | issueList = orderOutDetails.Select(item => new issueList |
| | | { |
| | | PickListID = item.ERPOrderId, |
| | | //åå¨å°ç¹ |
| | | WhCode = "205", |
| | | //颿æ°é |
| | | IssueQty = item.OutboundQuantity, |
| | | }).ToList() |
| | | |
| | | }; |
| | | var ERPProduction = GetERPIPAddress(SysConfigConst.ERPIPAddress, SysConfigConst.MaterialRequisition); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | |
| | | var result = await HttpsClient.PostAsync(ERPProduction, materialRequisition.ToJsonString()); |
| | | |
| | | var respone = JsonConvert.DeserializeObject<ResponeData>(result.ToString()); |
| | | if (respone.d.ResultStatus) |
| | | { |
| | | return content.OK(); |
| | | } |
| | | return content.Error(respone.d.ResultMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è°æ¨ |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | /// |
| | | public async Task ERPAllocate(DtStockInfo stock) |
| | | { |
| | | try |
| | | { |
| | | if (stock == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåä¿¡æ¯"); |
| | | } |
| | | Allocate allocate = new Allocate |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "TransIn002", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | |
| | | transferInList = stock.StockInfoDetails.Select(item => new transferInList |
| | | { |
| | | //ç©æç¼ç |
| | | ItemCode = item.MaterielCode, |
| | | //è°å
¥ä»åºå°å |
| | | TransInWHCode = "107", |
| | | //è°å
¥æ°é |
| | | TransInQty = item.Quantity, |
| | | // è°åºä»åºç¼ç |
| | | TransOutWHCode = item.WareHouseId, |
| | | }).ToList() |
| | | }; |
| | | var Allocate = GetERPIPAddress(SysConfigConst.ERPIPAddress, SysConfigConst.Allocate); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | var result = await HttpsClient.PostAsync(Allocate, allocate.ToJsonString()); |
| | | |
| | | var respone = JsonConvert.DeserializeObject<ResponeData>(result.ToString()); |
| | | if (!respone.d.ResultStatus) |
| | | { |
| | | throw new Exception(respone.d.ResultMsg); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public async Task ERPAllocateOut(DtStockInfo stock) |
| | | { |
| | | try |
| | | { |
| | | if (stock == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåä¿¡æ¯"); |
| | | } |
| | | Allocate allocate = new Allocate |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "TransIn002", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | |
| | | transferInList = stock.StockInfoDetails.Select(item => new transferInList |
| | | { |
| | | //ç©æç¼ç |
| | | ItemCode = item.MaterielCode, |
| | | //è°å
¥ä»åºå°å |
| | | TransInWHCode = "205", |
| | | //è°å
¥æ°é |
| | | TransInQty = item.Quantity, |
| | | // è°åºä»åºç¼ç |
| | | TransOutWHCode = "107", |
| | | }).ToList() |
| | | }; |
| | | var Allocate = GetERPIPAddress(SysConfigConst.ERPIPAddress, SysConfigConst.Allocate); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | var result = await HttpsClient.PostAsync(Allocate, allocate.ToJsonString()); |
| | | |
| | | var respone = JsonConvert.DeserializeObject<ResponeData>(result.ToString()); |
| | | if (!respone.d.ResultStatus) |
| | | { |
| | | throw new Exception(respone.d.ResultMsg); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | public async Task ERPAllocate(List<Dt_OrderOutDetails> orderOutDetails) |
| | | { |
| | | try |
| | | { |
| | | if (orderOutDetails.Count <= 0) |
| | | { |
| | | throw new Exception($"æªæ¾å°è°æ¨åºåºæ°æ®"); |
| | | } |
| | | List<transferInList> transferInList=new List<transferInList>(); |
| | | orderOutDetails.ForEach(x => |
| | | { |
| | | transferInList.Add(new transferInList |
| | | { |
| | | //ç©æç¼ç |
| | | ItemCode = x.MaterielCode, |
| | | //è°å
¥ä»åºå°å |
| | | TransInWHCode = x.AllocateWarehouseId, |
| | | //è°å
¥æ°é |
| | | TransInQty = x.OutboundQuantity, |
| | | // è°åºä»åºç¼ç |
| | | TransOutWHCode = "205", |
| | | }); |
| | | }); |
| | | Allocate allocate = new Allocate |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "TransIn002", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | transferInList = transferInList, |
| | | }; |
| | | var Allocate = GetERPIPAddress(SysConfigConst.ERPIPAddress, SysConfigConst.Allocate); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | var result = await HttpsClient.PostAsync(Allocate, allocate.ToJsonString()); |
| | | |
| | | var respone = JsonConvert.DeserializeObject<ResponeData>(result.ToString()); |
| | | if (!respone.d.ResultStatus) |
| | | { |
| | | throw new Exception($"ERPè°æ¨åºåº{respone.d.ResultMsg}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æå |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public async Task ERPMixedSend(List<Dt_OrderOutDetails> orderOutDetails) |
| | | { |
| | | try |
| | | { |
| | | if (orderOutDetails.Count <= 0) |
| | | { |
| | | throw new Exception($"æªæ¾å°è°æ¨åºåºæ°æ®"); |
| | | } |
| | | MixedSend send = new MixedSend |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "MiscShip001", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | |
| | | miscShipList = orderOutDetails.Select(item => new miscShipList |
| | | { |
| | | //ç©æç¼ç |
| | | ItemCode = item.MaterielCode, |
| | | //åå¨å°ç¹ç¼å· |
| | | WhCode = "205", |
| | | //æåæ°é |
| | | Qty = item.OutboundQuantity, |
| | | |
| | | BenefitDeptCode = "0505", |
| | | }).ToList() |
| | | }; |
| | | var ERPMixedSend = GetERPIPAddress(SysConfigConst.ERPIPAddress, SysConfigConst.MixedSend); |
| | | // åé请æ±å¹¶çå¾
ååº |
| | | var result = await HttpsClient.PostAsync(ERPMixedSend, send.ToJsonString()); |
| | | |
| | | var respone = JsonConvert.DeserializeObject<ResponeData>(result.ToString()); |
| | | if (!respone.d.ResultStatus) |
| | | { |
| | | throw new Exception($"ERPå
¶ä»åºåº{respone.d.ResultMsg}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// ææ¶ |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> ERPMixedReceive(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | DtStockInfo stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == palletCode); |
| | | MixedReceive allocate = new MixedReceive |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "TransIn002", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | |
| | | miscRcvList = stock.StockInfoDetails.Where(x => x.OutboundQuantity > 0).Select(item => new miscRcvList |
| | | { |
| | | ItemCode = item.MaterielCode, |
| | | WhCode = item.Warehouse, |
| | | Qty = item.OutboundQuantity, |
| | | CostPrice = 0, |
| | | }).ToList() |
| | | }; |
| | | return content.OK(data: allocate); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// éæ |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> ERPreturnMaterialList(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | DtStockInfo stock = await _stockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == palletCode); |
| | | ReturnMaterials allocate = new ReturnMaterials |
| | | { |
| | | context = new Context |
| | | { |
| | | CultureName = "zh-CN", |
| | | EntCode = "001", |
| | | OrgCode = "102", |
| | | UserCode = "MH0551" |
| | | }, |
| | | documentTypeCode = "TransIn002", |
| | | businessDate = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | isApproved = true, |
| | | |
| | | returnMaterialList = stock.StockInfoDetails.Select(item => new returnMaterialList |
| | | { |
| | | PickListID = item.MaterielCode, |
| | | WhCode = item.Warehouse, |
| | | RecedeQty = item.OutboundQuantity, |
| | | RecedeReason = 1, |
| | | }).ToList() |
| | | }; |
| | | return content.OK(data: allocate); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å
é¨è°ç¨æ¹æ³ |
| | | |
| | | public (List<DtLocationStatusChangeRecord>,List<DtLocationInfo>) UpdateLocationStatus(DtLocationInfo location, LocationEnum locationStatus, int taskNum, int StatusChangeType) |
| | | { |
| | | List<DtLocationInfo> locations = GetGroupLocations(location); |
| | | |
| | | List<DtLocationInfo> Beforelocation = locations.Select(x => new DtLocationInfo |
| | | { |
| | | Id = x.Id, |
| | | LocationCode = x.LocationCode, |
| | | LocationStatus = x.LocationStatus |
| | | }).ToList(); |
| | | |
| | | foreach (var item in locations) |
| | | { |
| | | if (locationStatus == LocationEnum.Lock) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Lock; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.FreeDisable; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.InStock) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.InStock; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.FreeDisable) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.InStockDisable) |
| | | { |
| | | if (item.LocationStatus == (int)LocationEnum.InStock) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.FreeDisable; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.Free) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.FreeDisable || item.LocationStatus == (int)LocationEnum.InStockDisable) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | } |
| | | } |
| | | List<DtLocationStatusChangeRecord> changeRecordDto = new List<DtLocationStatusChangeRecord>(); |
| | | foreach (var item in Beforelocation) |
| | | { |
| | | var loc = locations.Where(x => x.LocationCode == item.LocationCode).FirstOrDefault(); |
| | | if (loc != null) |
| | | { |
| | | DtLocationStatusChangeRecord dtLocationStatusChangeRecord = new DtLocationStatusChangeRecord() |
| | | { |
| | | ChangeType = StatusChangeType, |
| | | LocationCode = item.LocationCode, |
| | | LocationId = loc.Id, |
| | | Creater = "System", |
| | | TaskNum = taskNum, |
| | | AfterStatus = loc.LocationStatus, |
| | | BeforeStatus = item.LocationStatus, |
| | | }; |
| | | |
| | | changeRecordDto.Add(dtLocationStatusChangeRecord); |
| | | } |
| | | } |
| | | //_locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | |
| | | //_locationRepository.UpdateData(locations); |
| | | return (changeRecordDto,locations); |
| | | } |
| | | |
| | | public (List<DtLocationStatusChangeRecord>, List<DtLocationInfo>) UpdateLocationStatus(string locationCode, LocationEnum locationStatus, int taskNum, int StatusChangeType) |
| | | { |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == locationCode); |
| | | |
| | | List<DtLocationInfo> locations = GetGroupLocations(location); |
| | | |
| | | List<DtLocationInfo> Beforelocation = locations.Select(x => new DtLocationInfo |
| | | { |
| | | Id = x.Id, |
| | | LocationCode = x.LocationCode, |
| | | LocationStatus = x.LocationStatus |
| | | }).ToList(); |
| | | |
| | | foreach (var item in locations) |
| | | { |
| | | if (locationStatus == LocationEnum.Lock) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Lock; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.FreeDisable; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.InStock) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.InStock; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.FreeDisable) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.InStockDisable) |
| | | { |
| | | if (item.LocationStatus == (int)LocationEnum.InStock) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.FreeDisable; |
| | | } |
| | | } |
| | | else if (locationStatus == LocationEnum.Free) |
| | | { |
| | | if (item.LocationCode == location.LocationCode) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | else if (item.LocationStatus == (int)LocationEnum.FreeDisable || item.LocationStatus == (int)LocationEnum.InStockDisable) |
| | | { |
| | | item.LocationStatus = (int)LocationEnum.Free; |
| | | } |
| | | } |
| | | } |
| | | List<DtLocationStatusChangeRecord> changeRecordDto = new List<DtLocationStatusChangeRecord>(); |
| | | foreach (var item in Beforelocation) |
| | | { |
| | | var loc = locations.Where(x => x.LocationCode == item.LocationCode).FirstOrDefault(); |
| | | if (loc != null) |
| | | { |
| | | DtLocationStatusChangeRecord dtLocationStatusChangeRecord = new DtLocationStatusChangeRecord() |
| | | { |
| | | ChangeType = StatusChangeType, |
| | | LocationCode = item.LocationCode, |
| | | LocationId = loc.Id, |
| | | Creater = "System", |
| | | TaskNum = taskNum, |
| | | AfterStatus = loc.LocationStatus, |
| | | BeforeStatus = item.LocationStatus, |
| | | }; |
| | | |
| | | changeRecordDto.Add(dtLocationStatusChangeRecord); |
| | | } |
| | | } |
| | | //_locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | |
| | | //_locationRepository.UpdateData(locations); |
| | | return (changeRecordDto, locations); |
| | | } |
| | | |
| | | public List<DtLocationInfo> GetGroupLocations(DtLocationInfo location) |
| | | { |
| | | List<DtLocationInfo> locationInfos = _locationRepository.QueryData(x => x.AreaId == location.AreaId); |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>() { location }; |
| | | if (location.AreaId == 1) |
| | | { |
| | | if (location.Depth == 2) |
| | | { |
| | | DtLocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.Depth == 1 && x.Column == location.Column && x.Layer == location.Layer && x.Row == 1); |
| | | if (locationInfo != null) |
| | | { |
| | | locations.Add(locationInfo); |
| | | } |
| | | } |
| | | } |
| | | else if (location.AreaId == 2) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark); |
| | | if (locationLateral.Count > 0) |
| | | { |
| | | locations.AddRange(locationLateral); |
| | | } |
| | | } |
| | | else if (location.AreaId == 5 || location.AreaId == 6) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column < location.Column && x.Remark == location.Remark); |
| | | if (locationLateral.Count > 0) |
| | | { |
| | | locations.AddRange(locationLateral); |
| | | } |
| | | } |
| | | return locations; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建任å¡DTO |
| | | /// </summary> |
| | | private List<WMSTaskDTO> CreateListTaskDTO(Dt_Task task) |
| | | { |
| | | return new List<WMSTaskDTO> { new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | AGVTaskNum = task.AGVTaskNum, |
| | | } }; |
| | | } |
| | | |
| | | private WMSTaskDTO CreateTaskDTO(Dt_Task task) |
| | | { |
| | | return new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | AGVTaskNum = task.AGVTaskNum, |
| | | Remark= task.Remark |
| | | }; |
| | | } |
| | | |
| | | private async Task DeleteStockInfoAsync(int stockId) |
| | |
| | | } |
| | | } |
| | | |
| | | private async Task UpdateLocationAsync(DtLocationInfo info) |
| | | private async Task DeleteBoxingInfoAsync(int boxingId) |
| | | { |
| | | var isStockUpdated = await _locationRepository.UpdateDataAsync(info); |
| | | var isStockUpdated = await _stockInfoRepository.DeleteDataByIdAsync(boxingId); |
| | | if (!isStockUpdated) |
| | | { |
| | | throw new Exception("åºä½ä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | throw new Exception("åºåä¿¡æ¯æ´æ°å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | private async Task AddBoxingHtyAsync(DtBoxingInfo_Hty boxingInfo) |
| | | { |
| | | var isStockAdd = await SqlSugarHelper.DbWMS.InsertNav(boxingInfo).IncludesAllFirstLayer().ExecuteCommandAsync(); |
| | | if (!isStockAdd) |
| | | { |
| | | throw new Exception("ç»çåå²ä¿¡æ¯æ·»å 失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | private async Task DeleteStockInfoDetailsAsync(IEnumerable<DtStockInfoDetail> details) |
| | | { |
| | |
| | | throw new Exception("åå²ä»»å¡ä¿¡æ¯æ·»å 失败"); |
| | | } |
| | | } |
| | | |
| | | #endregion åºåºä»»å¡å®æ |
| | | |
| | | #region ç§»åºä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// ç§»åºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="saveModel">任塿°æ®åé</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> CompleteTransferTaskAsync(Dt_Task task, DtStockInfo stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // æ´æ°è´§ä½ååºåä¿¡æ¯ |
| | | (DtStockInfo updateStock, DtLocationInfo locationInForm, DtLocationInfo locationInfoTo) = UpdateStockLocation(stock, task); |
| | | var taskHty = CreateHistoricalTask(task); |
| | | LogFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "ç§»åºä»»å¡å®æ", $"è´§ä½å°åï¼{task.TargetAddress},ä¿®æ¹ååºåæ°æ®ï¼{JsonConvert.SerializeObject(updateStock)}ï¼åå
è´§ä½æ°æ®ï¼{locationInForm}"); |
| | | |
| | | // æ§è¡æ°æ®åºäºå¡ |
| | | bool isResult = false; |
| | | if (isResult) |
| | | content.OK("ç§»åºä»»å¡å®ææå"); |
| | | else |
| | | content.Error("ç§»åºä»»å¡å®æå¤±è´¥"); |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | Console.WriteLine(err.Message.ToString()); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | #endregion ç§»åºä»»å¡å®æ |
| | | |
| | | #region å
¥åºä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// 宿å
¥åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="task">任塿°æ®åé</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task) |
| | | { |
| | | // åå§åååºå
容 |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | #endregion å
¥åºä»»å¡å®æ |
| | | |
| | | #region ä»»å¡å®æ |
| | | |
| | | /// <summary> |
| | | /// å®æä»»å¡ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡ç¼å·</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | 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: |
| | | case (int)TaskInboundTypeEnum.InNG: |
| | | case (int)TaskInboundTypeEnum.InQuality: |
| | | LogFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "å
¥åºä»»å¡", ""); |
| | | return await CompleteInboundTaskAsync(task); |
| | | |
| | | case (int)TaskOutboundTypeEnum.OutTray: |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | case (int)TaskOutboundTypeEnum.OutNG: |
| | | |
| | | LogFactory.GetLog("ä»»å¡å®æ").InfoFormat(true, "åºåºä»»å¡", ""); |
| | | return await CompleteOutboundTaskAsync(task, stock); |
| | | |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | return await CompleteTransferTaskAsync(task, stock); |
| | | default: |
| | | return content.Error("ä»»å¡ç±»åä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | #endregion ä»»å¡å®æ |
| | | |
| | | #region 请æ±ä»»å¡å
¥åº |
| | | |
| | | public async Task<WebResponseContent> RequestTaskAsync(RequestTaskDto input) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | try |
| | | { |
| | | |
| | | } |
| | | catch (Exception err) |
| | | { |
| | | // æ´è¯¦ç»çå¼å¸¸å¤çï¼å¯ä»¥æ ¹æ®å¼å¸¸ç±»åè®°å½ä¸åçé误æ¥å¿ç |
| | | content.Error(err.Message); |
| | | Console.WriteLine(err.Message); |
| | | LogFactory.GetLog($"请æ±å
¥åºå¼å¸¸").Info(true, $"å¼å¸¸ä¿¡æ¯ã{err.Message}ãå¼å¸¸è¡ã{err.StackTrace}ã"); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡è´§ä½ |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | 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) |
| | | { |
| | | return content.Error(err.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 空æçå
¥åºç³è¯· |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> RequestTrayInTaskAsync(RequestTaskDto input) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | #endregion 请æ±ä»»å¡å
¥åº |
| | | |
| | | #region 请æ±åºåºï¼å®ç&空çï¼ |
| | | |
| | | /// <summary> |
| | | /// è¯·æ±æçä»»å¡ |
| | | /// </summary> |
| | | /// <param name="position">ç®æ ä½ç½®</param> |
| | | /// <param name="tag">æçç±»åï¼1ï¼å®çï¼2ï¼ç©ºçï¼</param> |
| | | /// <param name="areaCode">åºåç¼ç </param> |
| | | /// <param name="roadways">å··éç¼ç éå</param> |
| | | /// <returns>è¿åç»æé</returns> |
| | | public async Task<WebResponseContent> RequestTrayOutTaskAsync(string position, int tag, string areaCode, List<string> areaCodes, string productionLine) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | |
| | | // è¿åæåååº |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½å¼å¸¸ä¿¡æ¯å¹¶æåº |
| | | LogFactory.GetLog("è¯·æ±æçä»»å¡").Error(true, ex); |
| | | ConsoleHelper.WriteErrorLine("请æ±ç©º/宿çä»»å¡" + ex.Message + "\r\n" + ex.StackTrace); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建任å¡å®ä¾ |
| | | /// </summary> |
| | | private Dt_Task CreateTask(DtStockInfo stockInfo, string position, int tag) |
| | | { |
| | | return new Dt_Task |
| | | { |
| | | Grade = tag == 104 ? (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC") ? 1 : 2) : (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC") ? 2 : 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, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | Creater = "System", // ä¿®æ£æ¼åé误 |
| | | CreateDate = DateTime.Now, |
| | | TaskId = 0, |
| | | ProductionLine = stockInfo.ProductionLine, |
| | | ProcessCode = stockInfo.ProcessCode, |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建任å¡DTO |
| | | /// </summary> |
| | | private WMSTaskDTO CreateTaskDTO(Dt_Task task) |
| | | { |
| | | return new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState.Value, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | ProductionLine = task.ProductionLine, |
| | | }; |
| | | } |
| | | |
| | | #endregion 请æ±åºåºï¼å®ç&空çï¼ |
| | | |
| | | #region ä»»å¡ç¶ææ´æ¹ |
| | | |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ç¶æ&åºåºè§£ç |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <param name="taskState"></param> |
| | | /// <returns></returns> |
| | | 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)TaskInStatusEnum.SC_InFinish) |
| | | { |
| | | 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 ä»»å¡ç¶ææ´æ¹ |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | #region å
é¨è°ç¨æ¹æ³ |
| | | |
| | | public override WebResponseContent DeleteData(object[] key) |
| | | { |
| | |
| | | { |
| | | return await BaseDal.QueryFirstAsync(x => x.TaskNum == taskNum); |
| | | } |
| | | |
| | | public async Task<Dt_Task> GetByTaskAddress(string SourceAddress, string TargetAddress) |
| | | { |
| | | return await BaseDal.QueryFirstAsync(x => x.SourceAddress == SourceAddress|| x.TargetAddress== TargetAddress); |
| | | } |
| | | #endregion å
é¨è°ç¨æ¹æ³ |
| | | |
| | | #region private å
鍿¹æ³ |
| | |
| | | return taskHty; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°åºåä½ç½® |
| | | /// </summary> |
| | | /// <param name="stock">åºå对象</param> |
| | | /// <param name="toLocation">ç®æ ä½ç½®</param> |
| | | // æ´æ°åºååä½ç½®ä¿¡æ¯ |
| | | private (DtStockInfo, DtLocationInfo, DtLocationInfo) UpdateStockLocation(DtStockInfo stock, Dt_Task task) |
| | | { |
| | | //ä¿®æ¹æ¥æºåºä½å ç®æ åºä½ç¶æ |
| | | var fromLocation = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway); |
| | | fromLocation.LocationStatus = LocationEnum.Free.ObjToInt(); |
| | | var toLocation = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway); |
| | | toLocation.LocationStatus = LocationEnum.InStock.ObjToInt(); |
| | | |
| | | // å°åºåä½ç½®è®¾ç½®ä¸ºç®æ ä½ç½® |
| | | stock.LocationCode = task.TargetAddress; |
| | | |
| | | // è¿åæ´æ°åçåºååä½ç½®ä¿¡æ¯ |
| | | return (stock, fromLocation, toLocation); |
| | | } |
| | | |
| | | #region ä»»å¡è¯·æ±æ¹æ³ |
| | | |
| | | private static readonly SemaphoreSlim _semaphoreUpdate = new SemaphoreSlim(1, 1); |
| | | // æ´æ°ä»»å¡è´§ä½ |
| | | |
| | | private async Task<WebResponseContent> UpdateExistingTask(RequestTaskDto input, Dt_Task task) |
| | | { |
| | | await _semaphoreUpdate.WaitAsync(); |
| | | try |
| | | { |
| | | if (task == null) |
| | | { |
| | | return new WebResponseContent().Error("ä»»å¡å¯¹è±¡ä¸ºç©º"); |
| | | } |
| | | |
| | | try |
| | | { |
| | | // å建WebResponseContent对象 |
| | | var content = new WebResponseContent(); |
| | | |
| | | |
| | | var location = await GetEmptyLocation(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}"); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | finally { _semaphoreUpdate.Release(); } |
| | | } |
| | | |
| | | 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, |
| | |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = location.Id, |
| | | LocationCode = location.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticStorage, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticInbound, |
| | | }; |
| | | |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool isUpdateLo = await _locationRepository.UpdateDataAsync(location); |
| | | |
| | | return isResult && isUpdateLo && isTaskDetail; |
| | | return isResult && isUpdateLo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建æ°ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="input">è¯·æ±æ¨¡å</param> |
| | | /// <param name="process">å··é</param> |
| | | /// <param name="flag">æ è¯ï¼0-å
¥åºï¼1-空æçå
¥åºï¼2-NGå
¥åºï¼3-åºåºï¼</param> |
| | | /// <returns></returns> |
| | | private async Task<WebResponseContent> CreateNewTask(RequestTaskDto input, string productionLine, string processCode, List<string> process = null, int flag = 0) |
| | | private async Task<bool> AddTaskAsync(Dt_Task task, DtLocationInfo StartAddress, DtLocationInfo EndAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | //UpdateLocationStatus |
| | | bool isResult = await BaseDal.AddDataAsync(task) > 0; |
| | | int SourcebeforeStatus = StartAddress.LocationStatus; |
| | | |
| | | // è·åç®æ å°å |
| | | //string ToAddress = await GetRoadWayAsync(process); |
| | | string ToAddress = string.Empty; |
| | | if (flag < 2) |
| | | ToAddress = await GetRoadWayAsync(process); |
| | | else |
| | | ToAddress = process[0]; |
| | | if (string.IsNullOrEmpty(ToAddress)) |
| | | int TargetbeforeStatus = EndAddress.LocationStatus; |
| | | |
| | | StartAddress.LocationStatus = (int)LocationEnum.InStockDisable; |
| | | |
| | | EndAddress.LocationStatus = (int)LocationEnum.Lock; |
| | | |
| | | List<LocationChangeRecordDto> changeRecordDto = new List<LocationChangeRecordDto>() |
| | | { |
| | | return content.Error("æ æ³è·åç®æ å°å"); |
| | | } |
| | | // å建æ°ä»»å¡å®ä¾ |
| | | var task = new Dt_Task |
| | | { |
| | | CurrentAddress = input.Position, |
| | | Grade = 1, |
| | | Roadway = ToAddress, |
| | | TargetAddress = ToAddress, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = ToAddress, |
| | | OrderNo = null, |
| | | PalletCode = input.PalletCode, |
| | | SourceAddress = input.Position, |
| | | TaskState = flag == 3 ? (int)TaskOutStatusEnum.OutNew : (int)TaskInStatusEnum.InNew, |
| | | TaskType = flag == 0 ? (int)TaskInboundTypeEnum.Inbound : flag == 1 ? (int)TaskInboundTypeEnum.InTray : flag == 2 ? (int)TaskInboundTypeEnum.InNG : (int)TaskOutboundTypeEnum.Outbound, |
| | | TaskNum = await BaseDal.GetTaskNo(), |
| | | Creater = "System", |
| | | ProductionLine = productionLine, |
| | | ProcessCode = processCode |
| | | new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = StartAddress.LocationStatus, |
| | | BeforeStatus = SourcebeforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = StartAddress.Id, |
| | | LocationCode = StartAddress.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticInbound, |
| | | }, |
| | | new LocationChangeRecordDto() |
| | | { |
| | | AfterStatus = EndAddress.LocationStatus, |
| | | BeforeStatus = TargetbeforeStatus, |
| | | TaskNum = task.TaskNum.Value, |
| | | LocationId = EndAddress.Id, |
| | | LocationCode = EndAddress.LocationCode, |
| | | ChangeType = (int)StatusChangeTypeEnum.AutomaticInbound, |
| | | }, |
| | | }; |
| | | |
| | | // å°è¯æ·»å æ°ä»»å¡ |
| | | var taskId = await BaseDal.AddDataAsync(task); |
| | | bool isResult = taskId > 0; |
| | | if (isResult) |
| | | { |
| | | task.TaskId = taskId; |
| | | isResult = await _taskExecuteDetailRepository.AddDetailAsync(task, false, TaskDescription.GetTaskUpdateDescription(input.PalletCode, input.Position, ToAddress, TaskInStatusEnum.InNew.GetIntegralRuleTypeEnumDesc())); |
| | | bool isUpdateChange = _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); |
| | | bool Source = await _locationRepository.UpdateDataAsync(StartAddress); |
| | | bool Target = await _locationRepository.UpdateDataAsync(EndAddress); |
| | | |
| | | //var location = _locationRepository.QueryFirst(x => x.RoadwayNo == task.Roadway && x.LocationCode == task.TargetAddress); |
| | | //location.LocationStatus = (int)LocationEnum.Lock; |
| | | //var isLocation = _locationRepository.UpdateData(location); |
| | | |
| | | if (isResult) |
| | | { |
| | | // å建WMSä»»å¡ |
| | | WMSTaskDTO taskDTO = 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, |
| | | ProductionLine = task.ProductionLine |
| | | }; |
| | | content.OK(data: taskDTO); |
| | | } |
| | | else |
| | | content.Error("æ·»å ä»»å¡å¤±è´¥"); |
| | | } |
| | | else |
| | | content.Error("æ·»å ä»»å¡å¤±è´¥"); |
| | | return content; |
| | | return isResult && Source && Target; |
| | | } |
| | | |
| | | private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); |
| | | private static List<LocationCache> locationCaches = new List<LocationCache>(); |
| | | |
| | | /// <summary> |
| | | /// è·åè´§ä½å· |
| | |
| | | /// <returns></returns> |
| | | public async Task<DtLocationInfo> GetEmptyLocation(string roadWay) |
| | | { |
| | | await _semaphore.WaitAsync(); |
| | | try |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.RoadwayNo == "SC1" && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1); |
| | | if (locations.Count < 2) |
| | | { |
| | | List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 5).ToList();//æ¥è¯¢æ·»å éæåéè¶
è¿5åéçè´§ä½ |
| | | int count = removeItems.Count; |
| | | for (int i = 0; i < count; i++) |
| | | return null; |
| | | } |
| | | |
| | | List<DtLocationInfo> locationInfos = new List<DtLocationInfo>(); |
| | | var locationInside = locations.Where(x => x.Row == 3).ToList(); |
| | | |
| | | if (locations.Where(x => x.Row == 2).OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault() != null) |
| | | { |
| | | return locations.Where(x => x.Row == 2).ToList().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | else if (locationInside.Count > 0) |
| | | { |
| | | foreach (var item in locationInside) |
| | | { |
| | | locationCaches.Remove(removeItems[i]);//ç§»é¤æ¥è¯¢æ·»å éæåéè¶
è¿5åéçè´§ä½ |
| | | } |
| | | |
| | | List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList(); |
| | | |
| | | List<DtLocationInfo> LocationInfoList = await _locationRepository.QueryDataAsync(x => x.RoadwayNo == roadWay && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | |
| | | List<DtLocationInfo> LocationInfoResult = new List<DtLocationInfo>(); |
| | | foreach (DtLocationInfo item in LocationInfoList) |
| | | { |
| | | DtLocationInfo locationItem = new DtLocationInfo(); |
| | | |
| | | if (item.Depth == 2) |
| | | var locationLateral = _locationRepository.QueryFirst(x => x.Row == 1 && x.Layer == item.Layer && x.Column == item.Column); |
| | | if (locationLateral.LocationStatus == (int)LocationEnum.Free && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | locationItem = _locationRepository.QueryFirst(x => x.Column == item.Column && x.RoadwayNo == item.RoadwayNo && x.Layer == item.Layer && x.Depth != item.Depth && x.Row != item.Row && (SqlFunc.Abs(x.Row - item.Row) == 1) && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | if (locationItem != null) |
| | | { |
| | | LocationInfoResult.Add(item); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | locationItem = _locationRepository.QueryFirst(x => x.Column == item.Column && x.RoadwayNo == item.RoadwayNo && x.Layer == item.Layer && x.Depth != item.Depth && x.Row != item.Row && (SqlFunc.Abs(x.Row - item.Row) == 1) && x.LocationStatus == (int)LocationEnum.InStock && x.EnalbeStatus == EnableEnum.Enable.ObjToInt()); |
| | | if (locationItem != null) |
| | | { |
| | | LocationInfoResult.Add(item); |
| | | } |
| | | locationInfos.Add(item); |
| | | } |
| | | } |
| | | if (LocationInfoResult.Count < 2) |
| | | { |
| | | throw new Exception("å½å空é²è´§ä½ä¸è¶³ï¼"); |
| | | } |
| | | |
| | | return LocationInfoResult.Where(x => !lockLocations.Contains(x.LocationCode)).OrderByDescending(x => x.Depth).ThenBy(x => x.Column).ThenBy(x => x.Layer).FirstOrDefault(); |
| | | return locationInfos.Distinct().OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | catch (Exception ex) |
| | | else if (locations.Where(x => x.Row == 1).OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault() != null) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | return locations.Where(x => x.Row == 1).OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | } |
| | | finally |
| | | else |
| | | { |
| | | _semaphore.Release(); |
| | | return null; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®å··éè·åå··éæç«å° |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<string> GetRoadWayAsync(List<string> process) |
| | | |
| | | public async Task<DtLocationInfo> GetAGVEmptyCacheLocation(int AreaId, DtLocationInfo loc) |
| | | { |
| | | var deviceCode = await SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>() |
| | | .Where(x => x.DeviceStatus == 1.ToString() && process.Contains(x.DeviceCode)) |
| | | .Select(x => x.DeviceCode).ToListAsync(); |
| | | |
| | | var minGroup = _locationRepository.QueryData(x => deviceCode.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free) |
| | | .GroupBy(x => x.RoadwayNo) |
| | | .OrderByDescending(g => g.Count()) // æ ¹æ®æ¯ä¸ªç»çå
ç´ æ°éæåº |
| | | .ToList(); // ååºæ°éæå¤çç» |
| | | |
| | | Dictionary<string, int> result = new Dictionary<string, int>(); |
| | | foreach (var item in minGroup) |
| | | if (loc == null) |
| | | { |
| | | var number = BaseDal.QueryData(x => x.TargetAddress == item.Key && x.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup).Count(); |
| | | result.Add(item.Key, item.Count() - number); |
| | | return null; |
| | | } |
| | | switch (AreaId) |
| | | { |
| | | case 2: |
| | | return await FromShallowToDeep(AreaId, loc); |
| | | case 3: |
| | | return await AGVLIKU(AreaId); |
| | | case 5: |
| | | case 6: |
| | | return await FromDeepToShallow(AreaId, loc); |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç±æ·±å°æµ
|
| | | /// </summary> |
| | | /// <param name="AreaId"></param> |
| | | /// <returns></returns> |
| | | public async Task<DtLocationInfo> FromDeepToShallow(int AreaId, DtLocationInfo loc) |
| | | { |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | |
| | | if (AreaId == loc.AreaId) |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1 && x.Row != loc.Row); |
| | | } |
| | | else |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1); |
| | | } |
| | | if (locations.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | List<DtLocationInfo> locationInfos = new List<DtLocationInfo>(); |
| | | foreach (var item in locations) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == item.Row && x.Column < item.Column && x.Remark == item.Remark); |
| | | bool Isavailable = true; |
| | | foreach (var lateral in locationLateral) |
| | | { |
| | | if (lateral.LocationStatus != (int)LocationEnum.Free && lateral.EnalbeStatus == 1) |
| | | { |
| | | Isavailable = false; |
| | | continue; |
| | | } |
| | | } |
| | | if (Isavailable) |
| | | locationInfos.Add(item); |
| | | } |
| | | |
| | | string minRoadwayNo = result.OrderByDescending(x => x.Value).FirstOrDefault().Key; // æ°éæå¤çç»çKey |
| | | |
| | | return minRoadwayNo; |
| | | return locationInfos.Distinct().OrderByDescending(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç±æµ
å°æ·± |
| | | /// </summary> |
| | | /// <param name="AreaId"></param> |
| | | /// <returns></returns> |
| | | public async Task<DtLocationInfo> FromShallowToDeep(int AreaId, DtLocationInfo loc) |
| | | { |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | |
| | | if (AreaId == loc.AreaId) |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1 && x.Row != loc.Row); |
| | | } |
| | | else |
| | | { |
| | | locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1); |
| | | } |
| | | |
| | | if (locations.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | List<DtLocationInfo> locationInfos = new List<DtLocationInfo>(); |
| | | foreach (var item in locations) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == item.Row && x.Column > item.Column && x.Remark == item.Remark); |
| | | if (locationLateral.Count == 0) |
| | | { |
| | | locationInfos.Add(item); |
| | | continue; |
| | | } |
| | | foreach (var Lateral in locationLateral) |
| | | { |
| | | if (locationInfos.Contains(Lateral)) |
| | | continue; |
| | | if (Lateral.LocationStatus == (int)LocationEnum.Free && Lateral.EnalbeStatus == 1) |
| | | { |
| | | locationInfos.Add(item); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return locationInfos.Distinct().OrderBy(x => x.Column).ThenBy(x => x.Row).FirstOrDefault(); |
| | | |
| | | } |
| | | |
| | | |
| | | public async Task<DtLocationInfo> AGVLIKU(int AreaId) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | |
| | | List<DtLocationInfo> locations = await _locationRepository.QueryDataAsync(x => x.AreaId == AreaId && x.LocationStatus == 0 && x.EnalbeStatus == 1); |
| | | var location = locations.OrderBy(x => x.Layer).ThenBy(x => x.Column).FirstOrDefault(); |
| | | return location; |
| | | |
| | | } |
| | | |
| | | |
| | | public bool LocationIsOutBound(DtLocationInfo location) |
| | | { |
| | | |
| | | int sum = 0; |
| | | if (location.AreaId == 1) |
| | | { |
| | | if (location.Depth == 2) |
| | | { |
| | | var locationLateral = _locationRepository.QueryFirst(x => x.Row == 1 && x.Column == location.Column && x.Layer == location.Layer); |
| | | |
| | | if (locationLateral.LocationStatus == (int)LocationEnum.Lock && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | else if (location.AreaId == 2) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark); |
| | | |
| | | foreach (var Lateral in locationLateral) |
| | | { |
| | | if (Lateral.LocationStatus == (int)LocationEnum.Lock && Lateral.EnalbeStatus == 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | else if (location.AreaId == 5 || location.AreaId == 6) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column < location.Column && x.Remark == location.Remark); |
| | | |
| | | foreach (var lateral in locationLateral) |
| | | { |
| | | if (lateral.LocationStatus == (int)LocationEnum.Lock && lateral.EnalbeStatus == 1) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | |
| | | } |
| | | |
| | | |
| | | #endregion ä»»å¡è¯·æ±æ¹æ³ |
| | | |
| | | #endregion private å
鍿¹æ³ |