|  |  |  | 
|---|
|  |  |  | #endregion << ç æ¬ æ³¨ é >> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  | using HslCommunication.WebSocket; | 
|---|
|  |  |  | using MailKit.Search; | 
|---|
|  |  |  | using Microsoft.AspNetCore.Mvc.ApiExplorer; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; | 
|---|
|  |  |  | using SqlSugar; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.ComponentModel; | 
|---|
|  |  |  | using System.Diagnostics.CodeAnalysis; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Linq.Expressions; | 
|---|
|  |  |  | using System.Net.Http.Headers; | 
|---|
|  |  |  | using System.Reflection; | 
|---|
|  |  |  | using System.Reflection.Metadata; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | using System.Reflection.Emit; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | using WIDESEA_Common.CommonEnum; | 
|---|
|  |  |  | using WIDESEA_Common.LocationEnum; | 
|---|
|  |  |  | using WIDESEA_Common.OrderEnum; | 
|---|
|  |  |  | using WIDESEA_Common.StockEnum; | 
|---|
|  |  |  | using WIDESEA_Common.TaskEnum; | 
|---|
|  |  |  | using WIDESEA_Common.WareHouseEnum; | 
|---|
|  |  |  | using WIDESEA_Core; | 
|---|
|  |  |  | using WIDESEA_Core.BaseRepository; | 
|---|
|  |  |  | using WIDESEA_Core.BaseServices; | 
|---|
|  |  |  | using WIDESEA_Core.Enums; | 
|---|
|  |  |  | using WIDESEA_Core.Helper; | 
|---|
|  |  |  | using WIDESEA_Core.Log; | 
|---|
|  |  |  | using WIDESEA_DTO.Inbound; | 
|---|
|  |  |  | using WIDESEA_DTO.MES; | 
|---|
|  |  |  | using WIDESEA_DTO.Stock; | 
|---|
|  |  |  | using WIDESEA_DTO.Task; | 
|---|
|  |  |  | using WIDESEA_External.ERPService; | 
|---|
|  |  |  | using WIDESEA_External.Model; | 
|---|
|  |  |  | using WIDESEA_IBasicRepository; | 
|---|
|  |  |  | using WIDESEA_IBasicService; | 
|---|
|  |  |  | using WIDESEA_IInboundRepository; | 
|---|
|  |  |  | using WIDESEA_IInboundService; | 
|---|
|  |  |  | using WIDESEA_IOutboundRepository; | 
|---|
|  |  |  | using WIDESEA_IOutboundService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly IStockRepository _stockRepository; | 
|---|
|  |  |  | private readonly IBasicService _basicService; | 
|---|
|  |  |  | private readonly IRecordService _recordService; | 
|---|
|  |  |  | private readonly IOutboundService _outboundService; | 
|---|
|  |  |  | private readonly IStockService _stockService; | 
|---|
|  |  |  | private readonly IBasicRepository _basicRepository; | 
|---|
|  |  |  | private readonly IApiInfoRepository _apiInfoRepository; | 
|---|
|  |  |  | private readonly IInvokeERPService _invokeERPService; | 
|---|
|  |  |  | private readonly IInboundRepository _inboundRepository; | 
|---|
|  |  |  | private readonly IInboundOrderService _inboundOrderService; | 
|---|
|  |  |  | private readonly IPalletTypeInfoRepository _palletTypeInfoRepository; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public ITaskRepository Repository => BaseDal; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService) : base(BaseDal) | 
|---|
|  |  |  | private Dictionary<string, OrderByType> _taskOrderBy = new() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | {nameof(Dt_Task.Grade),OrderByType.Desc }, | 
|---|
|  |  |  | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<int> TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IOutboundService outboundService, IStockService stockService, IBasicRepository basicRepository, IApiInfoRepository apiInfoRepository, IInvokeERPService invokeERPService, IInboundRepository inboundRepository, IInboundOrderService inboundOrderService, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _mapper = mapper; | 
|---|
|  |  |  | _unitOfWorkManage = unitOfWorkManage; | 
|---|
|  |  |  | _stockRepository = stockRepository; | 
|---|
|  |  |  | _basicService = basicService; | 
|---|
|  |  |  | _recordService = recordService; | 
|---|
|  |  |  | _outboundService = outboundService; | 
|---|
|  |  |  | _stockService = stockService; | 
|---|
|  |  |  | _basicRepository = basicRepository; | 
|---|
|  |  |  | _apiInfoRepository = apiInfoRepository; | 
|---|
|  |  |  | _invokeERPService = invokeERPService; | 
|---|
|  |  |  | _inboundRepository = inboundRepository; | 
|---|
|  |  |  | _inboundOrderService = inboundOrderService; | 
|---|
|  |  |  | _palletTypeInfoRepository = palletTypeInfoRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public WebResponseContent RequestInboundTask(string palletCode, string stationCode) | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// ä»»å¡ä¿¡æ¯æ¨éè³WCS | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent PushTasksToWCS(List<Dt_Task> tasks, string agvDescription = "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode); | 
|---|
|  |  |  | if (task != null) | 
|---|
|  |  |  | List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks); | 
|---|
|  |  |  | taskDTOs.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"该æçå·²çæä»»å¡"); | 
|---|
|  |  |  | x.AGVArea = agvDescription; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | string url = AppSettings.Get("WCS"); | 
|---|
|  |  |  | if (string.IsNullOrEmpty(url)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°WCSApiå°å,è¯·æ£æ¥é
ç½®æä»¶"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°ç»çä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"该æçç¶æä¸æ£ç¡®,ä¸å¯ç³è¯·å
¥åº"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!string.IsNullOrEmpty(stockInfo.LocationCode)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"该æçå·²ç»å®è´§ä½"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //todo éè¿ç«å°å·æ¾å··éå· | 
|---|
|  |  |  | string roadwayNo = "RSC01"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PalletTypeEnum palletType = PalletTypeEnum.SmallPallet; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, palletType); | 
|---|
|  |  |  | if (locationInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"è´§ä½åé
失败,æªæ¾å°å¯åé
è´§ä½"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Task newTask = new Dt_Task() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | CurrentAddress = stationCode, | 
|---|
|  |  |  | Grade = 0, | 
|---|
|  |  |  | NextAddress = "", | 
|---|
|  |  |  | PalletCode = palletCode, | 
|---|
|  |  |  | Roadway = roadwayNo, | 
|---|
|  |  |  | SourceAddress = stationCode, | 
|---|
|  |  |  | TargetAddress = locationInfo.LocationCode, | 
|---|
|  |  |  | TaskType = TaskTypeEnum.Inbound.ObjToInt(), | 
|---|
|  |  |  | TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | int taskId = BaseDal.AddData(newTask); | 
|---|
|  |  |  | newTask.TaskId = taskId; | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundAssignLocation); | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, palletType, LocationStatusEnum.Lock); | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(data: newTask); | 
|---|
|  |  |  | return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("è¿åé误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æ¾è´§å®æ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="code"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent PutFinish(string code) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string url = AppSettings.Get("WCS"); | 
|---|
|  |  |  | if (string.IsNullOrEmpty(url)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°WCSAApiå°å,è¯·æ£æ¥é
ç½®æä»¶"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish", code); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("è¿åé误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// å
¥åºä»»å¡å®æ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskNum">ä»»å¡å·</param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent InboundTaskCompleted(int taskNum) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"ä»»å¡ç±»åé误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First(); | 
|---|
|  |  |  | Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode && x.WarehouseId == task.WarehouseId).Includes(x => x.Details).First(); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°æç对åºçç»çä¿¡æ¯"); | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"该æçå·²ç»å®è´§ä½"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (stockInfo.Details == null || stockInfo.Details.Count == 0) | 
|---|
|  |  |  | if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"è´§ä½ç¶æä¸æ£ç¡®"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; | 
|---|
|  |  |  | locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); | 
|---|
|  |  |  | stockInfo.LocationCode = locationInfo.LocationCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region ç©ºç®±å
¥åº/æ£éååº | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.InEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.InPick.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); | 
|---|
|  |  |  | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.äººå·¥å®æ : OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId); | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_InboundOrder? inboundOrder = _inboundRepository.InboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First(); | 
|---|
|  |  |  | List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>(); | 
|---|
|  |  |  | List<ERPInboundDetailModel> detailModels = new List<ERPInboundDetailModel>(); | 
|---|
|  |  |  | if (stockInfo.StockStatus == StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (inboundOrder == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"对åºå
¥åºåä¸åå¨"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | foreach (var item in stockInfo.Details) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.RowNo == item.InboundOrderRowNo); | 
|---|
|  |  |  | if (inboundOrderDetail == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ERPInboundDetailModel detailModel = new ERPInboundDetailModel() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ExpiryDate = item.EffectiveDate ?? "", | 
|---|
|  |  |  | LocationCode = warehouse.WarehouseCode, | 
|---|
|  |  |  | MaterialsCode = item.MaterielCode, | 
|---|
|  |  |  | MfgDate = item.ProductionDate ?? "", | 
|---|
|  |  |  | QtyCustoms = "0", | 
|---|
|  |  |  | Quantity = item.StockQuantity.ToString(), | 
|---|
|  |  |  | Rack = stockInfo.LocationCode, | 
|---|
|  |  |  | ReceiptCode = inboundOrder.UpperOrderNo, | 
|---|
|  |  |  | ReceiptSerNo = item.InboundOrderRowNo.ToString() | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | inboundOrderDetail.OverInQuantity += detailModel.Quantity.ObjToInt(); | 
|---|
|  |  |  | if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | inboundOrderDetails.Add(inboundOrderDetail); | 
|---|
|  |  |  | detailModels.Add(detailModel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //å
¥åºæç»æ°å¢å®ææ°é | 
|---|
|  |  |  | int newCount = inboundOrderDetails.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count; | 
|---|
|  |  |  | //å
¥åºæç»å宿æ°é | 
|---|
|  |  |  | int oldCount = inboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count; | 
|---|
|  |  |  | if (inboundOrder.Details.Count == (newCount + oldCount)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | inboundOrder.OrderStatus = InOrderStatusEnum.å
¥åºå®æ.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if ((stockInfo.StockStatus == StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt() || stockInfo.StockStatus == StockStatusEmun.æå¨ç»çå
¥åºç¡®è®¤.ObjToInt()) && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var model in stockInfo.Details) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TestSynStock(new TestToolSynInfo() { ToolCode = model.BatchNo, MaterialName = model.MaterielName, Life = int.TryParse(model.Remark, out int val) ? val : 1000 }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //æµè¯æ¶å
¥åºåºåç¶æ | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString() && stockInfo.StockStatus != StockStatusEmun.æå¨ç»çå
¥åºç¡®è®¤.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®ææªå»ºåºåºå.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | stockInfo.Details.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.Status = StockStatusEmun.å
¥åºå®æ.ObjToInt(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //æ´æ°ä»»å¡ç¶æ | 
|---|
|  |  |  | task.TaskStatus = (int)TaskStatusEnum.Finish; | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.äººå·¥å®æ : OperateTypeEnum.èªå¨å®æ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId); | 
|---|
|  |  |  | _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundAssignLocation); | 
|---|
|  |  |  | _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details); | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted); | 
|---|
|  |  |  | _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, stockInfo.Details.Sum(x => x.StockQuantity), stockInfo.Details.Sum(x => x.StockQuantity), StockChangeTypeEnum.Inbound, taskNum); | 
|---|
|  |  |  | if (inboundOrder != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetails); | 
|---|
|  |  |  | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  | if (stockInfo.StockStatus == StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _inboundOrderService.FeedbackInboundOrder(stockInfo, inboundOrder, detailModels); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// åºåºä»»å¡å®æ | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="taskNum">ä»»å¡å·</param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent OutboundTaskCompleted(int taskNum) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); | 
|---|
|  |  |  | if (task == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°ä»»å¡ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); | 
|---|
|  |  |  | if (stockInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°åºåä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (locationInfo == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°è´§ä½ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId); | 
|---|
|  |  |  | List<Dt_OutStockLockInfo> outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum); | 
|---|
|  |  |  | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); | 
|---|
|  |  |  | List<Dt_MesOutboundOrder> mesOutboundOrders = new List<Dt_MesOutboundOrder>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if ((outStockLockInfos == null || outStockLockInfos.Count == 0) && warehouse.WarehouseCode != WarehouseEnum.HA64.ToString() && task.TaskType != TaskTypeEnum.OutEmpty.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºè¯¦æ
ä¿¡æ¯"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var item in outStockLockInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.MesOutbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_MesOutboundOrder mesOutboundOrder = _outboundService.MesOutboundOrderService.Repository.QueryFirst(x => x.TaskNo == item.OrderNo); | 
|---|
|  |  |  | if (mesOutboundOrder != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | mesOutboundOrder.OverOutQuantity = item.AssignQuantity; | 
|---|
|  |  |  | if (mesOutboundOrder.OverOutQuantity == mesOutboundOrder.OrderQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | mesOutboundOrder.OrderStatus = OrderDetailStatusEnum.Over.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mesOutboundOrders.Add(mesOutboundOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == item.OrderDetailId); | 
|---|
|  |  |  | if (outboundOrderDetail != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | outboundOrderDetail.OverOutQuantity = item.AssignQuantity; | 
|---|
|  |  |  | if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | outboundOrderDetails.Add(outboundOrderDetail); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | item.Status = OutLockStockStatusEnum.åºåºå®æ.ObjToInt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); | 
|---|
|  |  |  | _unitOfWorkManage.BeginTran(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (outboundOrderDetails.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | stockInfo.LocationCode = ""; | 
|---|
|  |  |  | stockInfo.StockStatus = StockStatusEmun.åºåºå®æ.ObjToInt(); | 
|---|
|  |  |  | _stockService.StockInfoService.Repository.UpdateData(stockInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType == TaskTypeEnum.OutEmpty.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId); | 
|---|
|  |  |  | _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType == TaskTypeEnum.MesOutbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _outboundService.MesOutboundOrderService.Repository.UpdateData(mesOutboundOrders); | 
|---|
|  |  |  | _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); | 
|---|
|  |  |  | _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfos); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int beforeStatus = locationInfo.LocationStatus; | 
|---|
|  |  |  | locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); | 
|---|
|  |  |  | _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, (LocationStatusEnum)beforeStatus, LocationStatusEnum.Free, LocationChangeType.OutboundCompleted, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); | 
|---|
|  |  |  | _unitOfWorkManage.CommitTran(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (warehouse.WarehouseCode != WarehouseEnum.HA64.ToString() && task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _outboundService.OutboundOrderService.TestOutUpload(outboundOrderDetails.FirstOrDefault().OrderId, outStockLockInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.MesOutbound.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MesMaterialLotaAceptModel model = GetMesMaterialLotaAceptModel(stockInfo, stockInfo.Details.FirstOrDefault(), mesOutboundOrders.FirstOrDefault().TaskNo, warehouse.WarehouseCode, mesOutboundOrders.FirstOrDefault().OrderQuantity); | 
|---|
|  |  |  | UploadMesMaterialLotaAcept(model); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _unitOfWorkManage.RollbackTran(); | 
|---|
|  |  |  | return WebResponseContent.Instance.Error(ex.Message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|