1
dengjunjie
2025-09-29 d9c99e0480b4910cdb134778dd5c314b35ec4cf2
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -267,7 +267,7 @@
                    return webResponse.Error($"批号【{batchNo}】已质检入库");
                List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoRepository.QueryData(x => x.BatchNo == batchNo && x.StockStatus == StockStatusEmun.已入库.ObjToInt()).OrderByDescending(x => x.InDate).Take(qty).ToList();
                if (_InventoryInfos.Count < 1) return webResponse.Error($"未找到批号【{batchNo}】的库存");
                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == _InventoryInfos.First().LocationCode);
                List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => _InventoryInfos.Select(x => x.LocationCode).ToList().Contains(x.LocationCode));
                List<Dt_Task> tasks = new List<Dt_Task>();
                List<Dt_OutStockLockInfo> OutStockLockInfos = new List<Dt_OutStockLockInfo>();
                #region ç”Ÿæˆè´¨æ£€å‡ºåº“单
@@ -289,6 +289,7 @@
                #endregion
                foreach (var item in _InventoryInfos)
                {
                    var locationInfo = locationInfos.First(x => x.LocationCode == item.LocationCode);
                    orderDetail.MaterielCode = item.MaterielCode;
                    orderDetail.MaterielName = item.MaterielName;
                    orderDetail.OrderQuantity += item.StockQuantity;
@@ -301,10 +302,10 @@
                        Grade = 0,
                        PalletCode = item.PalletCode,
                        SourceIsPickPlace = item.SerialNumber == locationInfo.MaxQty,
                        NextAddress = "1005",
                        NextAddress = "1008",
                        Roadway = "SC01",
                        SourceAddress = item.LocationCode,
                        TargetAddress = "1005",
                        TargetAddress = "1008",
                        TaskState = OutTaskStatusEnum.OutNew.ObjToInt(),
                        TaskType = TaskTypeEnum.OutQuality.ObjToInt(),
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
@@ -331,7 +332,7 @@
                    OutStockLockInfos.Add(outStockLockInfo);
                    #endregion
                }
                bool CreateQCIn = AppSettings.app(nameof(CreateQCIn)).ObjToBool();
                #region ç”Ÿæˆè´¨æ£€å…¥åº“单
                Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
                {
@@ -364,7 +365,7 @@
                BaseDal.AddData(tasks);
                _outboundService.OutboundOrderService.Repository.Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                _outboundService.OutboundStockLockInfoService.Repository.AddData(OutStockLockInfos);
                _inboundService.InbounOrderService.Repository.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                if (CreateQCIn) _inboundService.InbounOrderService.Repository.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                _inventoryInfoRepository.UpdateData(_InventoryInfos);
                _inventoryBatchRepository.UpdateData(inventory_Batch);
                #region ä¸‹å‘任务给WCS
@@ -394,15 +395,15 @@
                if (inventoryInfo == null) throw new Exception("未找到托盘信息");
                if (inventoryInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.入库确认.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.入库中.ObjToInt())
                    throw new Exception($"托盘非入库中,不可修改数量");
                Dt_InboundOrderDetail orderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                //Dt_InboundOrderDetail orderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                var StockQty = inventoryInfo.StockQuantity;
                inventoryInfo.StockQuantity = qty;
                inventoryInfo.BoxQuantity = qty % 8 > 0 ? qty / 8 + 1 : qty / 8;
                if (orderDetail != null)
                {
                    orderDetail.ReceiptQuantity -= StockQty - qty;
                    _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
                }
                //if (orderDetail != null)
                //{
                //    orderDetail.ReceiptQuantity -= StockQty - qty;
                //    _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
                //}
                _inventoryInfoRepository.UpdateData(inventoryInfo);
                return webResponseContent.OK();
            }
@@ -411,7 +412,38 @@
                return webResponseContent.Error(ex.Message);
            }
        }
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.TaskId == saveModel.MainData["taskId"].ObjToInt());
                string newBarcode = saveModel.MainData["palletCode"].ToString();
                if (TaskEnumHelper.GetTaskTypeGroup(dt_Task.TaskType) != TaskTypeGroup.InboundGroup)
                    throw new Exception($"只可修改入库任务,如需修改其他任务类型请联系管理员!");
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == newBarcode);
                if (inventoryInfo != null) throw new Exception($"托盘号【{newBarcode}】已存在库存信息!");
                inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == dt_Task.PalletCode);
                if (inventoryInfo == null) throw new Exception($"托盘号【{dt_Task.PalletCode}】未找到库存信息!");
                inventoryInfo.PalletCode = newBarcode;
                dt_Task.PalletCode = newBarcode;
                Db.Ado.BeginTran();
                WMSTaskDTO wMSTaskDTOs = _mapper.Map<WMSTaskDTO>(dt_Task);
                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ModifyBarcode, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"WCS响应超时");
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                if (content == null) throw new Exception($"WCS无响应");
                if (!content.Status) throw new Exception(content.Message);
                BaseDal.UpdateData(dt_Task);
                _inventoryInfoRepository.UpdateData(inventoryInfo);
                Db.Ado.CommitTran();
                return webResponseContent.OK();
            }
            catch (Exception ex)
            {
                return webResponseContent.Error(ex.Message);
            }
        }
        public WebResponseContent ModifyBarcode(string barcode, string newBarcode)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
@@ -460,23 +492,36 @@
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == WMStask.TaskNum && x.TaskType == WMStask.TaskType);
                if (task == null) return WebResponseContent.Instance.Error("未找到任务信息");
                Dt_StockInfo? _StockInfo = _stockService.StockInfoService.GetStockByPalletCode(task.PalletCode);
                if (_StockInfo != null)
                Dt_InventoryInfo? inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
                if (inventoryInfo != null)
                {
                    Dt_StockInfoDetail? detail = _StockInfo.Details.FirstOrDefault();
                    if (detail != null)
                    Dt_InboundOrderDetail? inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                    if (inboundOrderDetail != null)
                    {
                        Dt_InboundOrder dt_InboundOrder = _inboundService.InbounOrderService.GetInboundOrder(detail.OrderNo);
                        Dt_InboundOrderDetail? inboundOrderDetail = dt_InboundOrder.Details.FirstOrDefault(x => x.BatchNo == detail.BatchNo);
                        if (inboundOrderDetail != null)
                        {
                            inboundOrderDetail.ReceiptQuantity--;
                            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                        }
                        _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(_StockInfo.Details, OperateType.AGV删除);
                        inboundOrderDetail.ReceiptQuantity--;
                        _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                    }
                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(_StockInfo, OperateType.AGV删除);
                    _inventoryInfoRepository.DeleteAndMoveIntoHty(inventoryInfo, OperateType.AGV删除);
                }
                #region MyRegion
                //Dt_StockInfo? _StockInfo = _stockService.StockInfoService.GetStockByPalletCode(task.PalletCode);
                //if (_StockInfo != null)
                //{
                //    Dt_StockInfoDetail? detail = _StockInfo.Details.FirstOrDefault();
                //    if (detail != null)
                //    {
                //        Dt_InboundOrder dt_InboundOrder = _inboundService.InbounOrderService.GetInboundOrder(detail.OrderNo);
                //        Dt_InboundOrderDetail? inboundOrderDetail = dt_InboundOrder.Details.FirstOrDefault(x => x.BatchNo == detail.BatchNo);
                //        if (inboundOrderDetail != null)
                //        {
                //            inboundOrderDetail.ReceiptQuantity--;
                //            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                //        }
                //        _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(_StockInfo.Details, OperateType.AGV删除);
                //    }
                //    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(_StockInfo, OperateType.AGV删除);
                //}
                #endregion
                BaseDal.DeleteAndMoveIntoHty(task, /*App.User.UserId == 0 ? OperateType.自动完成 :*/ OperateType.AGV删除);
            }
            catch (Exception ex)
@@ -681,43 +726,43 @@
            {
                Db.Ado.BeginTran();
                Dt_OutStockLockInfo? outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum && x.PalletCode == task.PalletCode);
                Dt_OutboundOrder? outboundOrder = null;
                Dt_OutboundOrderDetail? outboundOrderDetail = null;
                //Dt_OutboundOrder? outboundOrder = null;
                //Dt_OutboundOrderDetail? outboundOrderDetail = null;
                int overCount = 0;
                if (outStockLockInfo != null)
                {
                    outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId);
                    if (outboundOrderDetail != null)
                    {
                        outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
                        if (outboundOrder != null)
                        {
                            outboundOrderDetail.OverOutQuantity++;
                            overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                            if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
                            {
                                var outboundOrderdetail = outboundOrder.Details.First(x => x.Id == outboundOrderDetail.Id);
                                outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                                outboundOrderdetail.OverOutQuantity = outboundOrderDetail.OverOutQuantity;
                                outboundOrderdetail.OrderDetailStatus = outboundOrderDetail.OrderDetailStatus;
                                overCount++;
                            }
                        }
                    }
                    //outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId);
                    //if (outboundOrderDetail != null)
                    //{
                    //    outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
                    //    if (outboundOrder != null)
                    //    {
                    //        outboundOrderDetail.OverOutQuantity += outStockLockInfo.AssignQuantity;
                    //        overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                    //        if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
                    //        {
                    //            var outboundOrderdetail = outboundOrder.Details.First(x => x.Id == outboundOrderDetail.Id);
                    //            outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    //            outboundOrderdetail.OverOutQuantity = outboundOrderDetail.OverOutQuantity;
                    //            outboundOrderdetail.OrderDetailStatus = outboundOrderDetail.OrderDetailStatus;
                    //            overCount++;
                    //        }
                    //    }
                    //}
                    outStockLockInfo.Status = OutLockStockStatusEnum.出库完成.ObjToInt();
                }
                if (outboundOrder != null && outboundOrder.Details.Count == overCount)
                {
                    outboundOrder.OrderStatus = OutboundStatusEnum.出库完成.ObjToInt();
                    _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    outboundOrder.Details = null;
                    _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                }
                else
                {
                    if (outboundOrderDetail != null)
                        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetail);
                }
                //if (outboundOrder != null && outboundOrder.Details.Count == overCount)
                //{
                //    outboundOrder.OrderStatus = OutboundStatusEnum.出库完成.ObjToInt();
                //    _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                //    outboundOrder.Details = null;
                //    _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                //}
                //else
                //{
                //    if (outboundOrderDetail != null)
                //        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetail);
                //}
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                if (outStockLockInfo != null) _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo);
                Db.Ado.CommitTran();