647556386
3 天以前 3460ffdc967b65ea67c959212c2505a19008401e
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs
@@ -70,6 +70,7 @@
        public readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
        public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
        public readonly IRepository<Dt_LocationType> _locationTypeRepository;
        public readonly IRepository<Dt_OutboundOrderDetail> _outboundOrderDetailRepository;
        private Dictionary<string, string> stations = new Dictionary<string, string>
        {
@@ -83,7 +84,7 @@
            {"3-1","3-5" },
        };
        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository)
        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -110,6 +111,7 @@
            _inboundOrderRepository = inboundOrderRepository;
            _locationTypeRepository = locationTypeRepository;
            _warehouseAreaRepository = warehouseAreaRepository;
            _outboundOrderDetailRepository = outboundOrderDetailRepository;
        }
        public WebResponseContent PrintFromData (string barcode)
@@ -356,7 +358,7 @@
                _detailRepository.UpdateData(outboundOrderDetails);
                if (pickedDetails.Any())
                {
                    UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.出库锁定.ObjToInt());
                    UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.出库锁定.ObjToInt(),outboundOrder);
                    UpdateLocationStatus(pickedDetails.Select(x => x.LocationCode).ToList(), LocationStatusEnum.Lock.ObjToInt());
                }
                //重检单不拣选,去掉锁定记录回库,再次组盘时扣除原条码
@@ -982,11 +984,16 @@
            }
        }
        public bool UpdateStockStatus(List<string> palletCodes, int status)
        public bool UpdateStockStatus(List<string> palletCodes, int status,Dt_OutboundOrder outOrder)
        {
            try
            {
                List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => palletCodes.Contains(x.PalletCode));
                ///智仓调智仓单据记录
                if(outOrder.OrderType == 117)
                {
                    stockInfos.ForEach(stockInfo => stockInfo.Remark = outOrder.OrderNo);
                }
                stockInfos.ForEach(stockInfo => stockInfo.StockStatus = status);
                _stockInfoRepository.UpdateData(stockInfos);
                return true;
@@ -2249,6 +2256,48 @@
                    return content.Error($"未找到托盘{palletCode}库存信息不允许回库");
                }
                var task = await _taskRepository.Db.Queryable<Dt_Task>()
                    .Where(x => x.PalletCode == palletCode)
                    .FirstAsync();
                if (task != null)
                {
                    return content.Error($"托盘{palletCode}存在任务回库失败!");
                }
                // åˆ†é…æ–°è´§ä½
                var newLocation = _locationInfoService.AssignLocation(stock.LocationType);
                if (newLocation == null)
                {
                    return WebResponseContent.Instance.Error("没有空闲库位可回库");
                }
                if(stock.Remark !=null && stock.Remark != "")
                {
                    Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == stock.Remark && x.OrderType == 117 && x.OrderStatus == OutOrderStatusEnum.出库中.ObjToInt());
                    if (outboundOrder != null)
                    {
                        // 1. æ ¹æ®è®¢å•号查询调拨物料信息
                        List<Dt_AllocateMaterialInfo> allocateMaterialInfos = _allocateMaterialInfoRepository.QueryData(x => x.OrderNo == outboundOrder.OrderNo);
                        // 2. åˆ¤æ–­æ˜¯å¦å­˜åœ¨è°ƒæ‹¨ç‰©æ–™ï¼Œæ²¡æœ‰åˆ™ç›´æŽ¥è·³è¿‡æ ¡éªŒ
                        if (allocateMaterialInfos != null && allocateMaterialInfos.Any())
                        {
                            // 3. æå–所有 Barcode é›†åˆ
                            List<string> barcodes = allocateMaterialInfos.Select(x => x.Barcode).ToList();
                            // 4. æ ¹æ® Barcode æ‰¹é‡æŸ¥è¯¢åº“存明细
                            List<Dt_StockInfoDetail> stockInfoDetails = _stockDetailRepository.QueryData(x => barcodes.Contains(x.Barcode) && x.OrderNo == outboundOrder.OrderNo);
                            // 5. æ•°é‡å¯¹æ¯”:不相等 â†’ æœªå…¨éƒ¨ç»„盘完成
                            if (barcodes.Count != stockInfoDetails.Count)
                            {
                                return WebResponseContent.Instance.Error($"智仓调智仓单据{outboundOrder.OrderNo}尚未全部组盘完成,请先进行组盘再回库单据相关料箱");
                            }
                        }
                    }
                }
                if (stock.Details.Count <= 0)
                {
                    stock.PalletType = (int)PalletTypeEnum.Empty;
@@ -2352,23 +2401,6 @@
                    stock.StockStatus = (int)StockStatusEmun.入库确认;
                    stock.LocationCode = "";
                }
                var task = await _taskRepository.Db.Queryable<Dt_Task>()
                    .Where(x => x.PalletCode == palletCode)
                    .FirstAsync();
                if (task != null)
                {
                    return content.Error($"托盘{palletCode}存在任务回库失败!");
                }
                // åˆ†é…æ–°è´§ä½
                var newLocation = _locationInfoService.AssignLocation(stock.LocationType);
                if(newLocation == null)
                {
                    return WebResponseContent.Instance.Error("没有空闲库位可回库");
                }
                var newTask = new Dt_Task()
@@ -2504,10 +2536,9 @@
                Dt_StockInfoDetail_Hty historyDetail = _stockDetailHistoryRepository.QueryFirst(x =>
                    x.Barcode == request.Barcode &&
                    (x.OperateType == "出库完成" || x.OperateType == "拆包-原始记录"));
                if(historyDetail != null)
                if (historyDetail != null)
                {
                    double minutesDiff = (DateTime.Now - historyDetail.InsertTime).TotalMinutes;
                    if (minutesDiff >= 30)
@@ -2530,6 +2561,41 @@
                {
                    return WebResponseContent.Instance.Error("该托盘已全部拣选完,不允许撤销");
                }
               var details = _outboundOrderDetailRepository.QueryData(x => x.OrderId == outboundOrder.Id);
                var outboundDetails = details
                    .Where(x =>
                        x.MaterielCode == historyDetail.MaterielCode
                        &&
                        !string.IsNullOrEmpty(lockInfo.OrderDetailIds)
                        &&
                        lockInfo.OrderDetailIds.Split(",")
                            .Any(idStr => idStr.Trim() == x.Id.ToString())
                    ).ToList();
                var detail = outboundDetails.FirstOrDefault();
                if (detail != null && !string.IsNullOrEmpty(detail.ReturnJsonData))
                {
                    try
                    {
                        string deleteBarcode = request.Barcode;
                        var list = JsonConvert.DeserializeObject<List<BarcodeItem>>(detail.ReturnJsonData);
                        if (list != null)
                        {
                            var filteredList = list.Where(x => x.barcode != deleteBarcode).ToList();
                            detail.ReturnJsonData = JsonConvert.SerializeObject(filteredList);
                            _outboundOrderDetailRepository.UpdateData(detail);
                        }
                    }
                    catch
                    {
                    }
                }
                _unitOfWorkManage.BeginTran();
                try
                {
@@ -2542,21 +2608,11 @@
                    {
                        ReverseFullOutboundOperation(historyDetail, stockInfo, request);
                    }
                    RollbackOutboundOrderDetails(historyDetail.MaterielCode, request.OrderNo, historyDetail.StockQuantity, stockInfo.Id);
                    if (lockInfo != null)
                    {
                        lockInfo.SortedQuantity = Math.Max(0, (decimal)(lockInfo.SortedQuantity - historyDetail.StockQuantity));
                        if (lockInfo.SortedQuantity == 0)
                        {
                            _outboundLockInfoRepository.UpdateData(lockInfo);
                        }
                        else
                        {
                            _outboundLockInfoRepository.UpdateData(lockInfo);
                        }
                    }
                    lockInfo.SortedQuantity = Math.Max(0, (decimal)(lockInfo.SortedQuantity - historyDetail.StockQuantity));
                    _outboundLockInfoRepository.UpdateData(lockInfo);
                    _stockDetailHistoryRepository.DeleteData(historyDetail);
@@ -2769,4 +2825,35 @@
       
    }
    /// <summary>
    /// æ¡ç æ˜Žç»†å®žä½“
    /// </summary>
    public class BarcodeItem
    {
        /// <summary>
        /// æ¡ç 
        /// </summary>
        public string barcode { get; set; }
        /// <summary>
        /// æ•°é‡
        /// </summary>
        public decimal qty { get; set; }
        /// <summary>
        /// ä¾›åº”商编码
        /// </summary>
        public string supplyCode { get; set; }
        /// <summary>
        /// æ‰¹æ¬¡å·
        /// </summary>
        public string batchNo { get; set; }
        /// <summary>
        /// å•位
        /// </summary>
        public string unit { get; set; }
    }
}