heshaofeng
7 天以前 461524a7a1def4532b9af4ab40733f899f360db7
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs
@@ -1,6 +1,8 @@
using LogLibrary.Log;
using MailKit;
using MailKit.Net.Smtp;
using MailKit.Search;
using Microsoft.AspNetCore.Http;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Bcpg;
@@ -58,7 +60,8 @@
        private readonly ILocationInfoService _locationInfoService;
        private readonly IRepository<Dt_TakeStockOrder> _takeStockOrder;
        private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository;
        public InboundService(IUnitOfWorkManage unitOfWorkManage, IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IStockService stockService, IRepository<Dt_Task> taskRepository,IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord,ILocationInfoService locationInfoService,IRepository<Dt_TakeStockOrder> takeStockOrder,IRepository<Dt_StockInfoDetail> stockInfoDetailRepository)
        private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
        public InboundService(IUnitOfWorkManage unitOfWorkManage, IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IStockService stockService, IRepository<Dt_Task> taskRepository,IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord,ILocationInfoService locationInfoService,IRepository<Dt_TakeStockOrder> takeStockOrder,IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository)
        {
            _unitOfWorkManage = unitOfWorkManage;
            InboundOrderDetailService = inboundOrderDetailService;
@@ -76,9 +79,11 @@
            _locationInfoService = locationInfoService;
            _takeStockOrder = takeStockOrder;
            _stockInfoDetailRepository = stockInfoDetailRepository;
            _allocateOrderRepository = allocateOrderRepository;
        }
        public async Task<WebResponseContent> GroupPallet(GroupPalletDto palletDto)
        public async Task<WebResponseContent>
            GroupPallet(GroupPalletDto palletDto)
        {
            WebResponseContent content = new WebResponseContent();
            try
@@ -148,10 +153,22 @@
                    return content.Error($"当前厂区不一致");
                }
                if(inboundOrder.BusinessType != "11"&& inboundOrder.Details.FirstOrDefault().WarehouseCode != palletDto.WarehouseType)
                if(inboundOrder.BusinessType != "11")
                {
                    return content.Error($"该条码所属仓库为{inboundOrder.Details.FirstOrDefault().WarehouseCode}与当前仓库{palletDto.WarehouseType}不一致,不允许组盘");
                    var warehouseType = _inboundOrderDetailRepository.Db.Queryable<Dt_InboundOrderDetail>().Where(x => (x.Barcode == palletDto.Barcode || x.OutBoxbarcodes == palletDto.Barcode)&& x.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()).Select(x => x.WarehouseCode).First();
                    if (string.IsNullOrEmpty(warehouseType))
                    {
                        return content.Error($"未查询到条码[{palletDto.Barcode}]对应的仓库信息,不允许组盘");
                    }
                    if (!warehouseType.Equals(palletDto.WarehouseType))
                    {
                        return content.Error($"该条码所属仓库为{warehouseType}与当前仓库{palletDto.WarehouseType}不一致,不允许组盘");
                    }
                }
                Dt_StockInfo? stockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletDto.PalletCode).FirstAsync();
@@ -166,6 +183,20 @@
                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = Convert.ToInt32(palletDto.locationType) };
                    stockInfo.Details = new List<Dt_StockInfoDetail>();
                }
                //else
                //{
                //      var allowStatus = new[]
                //  {
                //      (int)StockStatusEmun.组盘暂存,
                //      (int)StockStatusEmun.智仓入智仓组盘暂存,
                //      (int)StockStatusEmun.手动组盘暂存
                //  };
                //    if (!allowStatus.Contains(stockInfo.StockStatus))
                //    {
                //        return content.Error($"该托盘{stockInfo.PalletCode}状态不允许组盘");
                //    }
                //}
                if (inboundOrder.BusinessType != MESDocumentType.PurchaseInbound.ToString() && stockInfo != null && stockInfo.Details.Count > 0 && stockInfo.Details.FirstOrDefault()?.WarehouseCode != palletDto.WarehouseType)
                {
@@ -180,6 +211,10 @@
                if (inboundOrder.BusinessType == "11" && inboundOrder.IsTestMaterials == 1 && palletDto.WarehouseType != "1076" && palletDto.WarehouseType != "5057")
                {
                    return content.Error($"该单据为试产物料,需要入库到试产仓,请重新根据厂区选择试产仓库进行组盘入库");
                }
                if (inboundOrder.IsTestMaterials == 0 && (palletDto.WarehouseType == "1076" || palletDto.WarehouseType == "5057"))
                {
                    return content.Error($"该单据为非试产物料,不能入到试产仓,请重新根据仓库进行组盘入库");
                }
                if (!_locationInfoService.QueryLocationCount(Convert.ToInt32(palletDto.locationType)))
                {
@@ -443,9 +478,27 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
                Dt_InboundOrder inboundOrder = null;
                var allocateOrder = _allocateOrderRepository.Db.Queryable<Dt_AllocateOrder>().Where(x => x.Id == id).First();
                if (allocateOrder != null)
                {
                    inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == allocateOrder.OrderNo).First();
                    if (inboundOrder.IsBatch == 0 && inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                    {
                        return content = WebResponseContent.Instance.OK($"该单据属于不分批自动回传,不可手动分批回传");
                    }
                }else
                {
                    inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
                                    .Where(x => x.Id == id)
                                    .First();
                    if (inboundOrder.IsBatch == 0 && inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                    {
                        return content = WebResponseContent.Instance.OK($"该单据属于不分批自动回传,不可手动分批回传");
                    }
                }
                List<Dt_MesReturnRecord> returnRecords = _mesReturnRecord.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo && x.OrderId == inboundOrder.Id && x.ReturnStatus == 2);
                foreach (var item in returnRecords)
@@ -536,7 +589,18 @@
                    {
                        if (returnRecords.Count() == returnRecords.Count(x => x.ReturnStatus == 1))
                        {
                            inboundOrder.ReturnToMESStatus = 1;
                            if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                            {
                                inboundOrder.ReturnToMESStatus = 1;
                            }
                            else if (inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                            {
                                inboundOrder.ReturnToMESStatus = 3;
                            }
                            else
                            {
                                inboundOrder.ReturnToMESStatus = 0;
                            }
                        }
                        else if (returnRecords.Count(x => x.ReturnStatus == 2) > 0)
                        {
@@ -547,15 +611,31 @@
                            inboundOrder.ReturnToMESStatus = 2;
                        }
                        _inboundOrderRepository.UpdateData(inboundOrder);
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,失败数据回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                    }
                    var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
                    if (response != null && response.IsSuccess)
                    if (response != null && response.IsSuccess && response.Data.Code == "200")
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                        .Where(it => it.OrderId == inboundOrder.Id && inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else if (inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 0 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
                        {
@@ -566,6 +646,22 @@
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
                         .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else if (inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 0 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        return content.Error("回传MES失败");
                    }
                }
@@ -588,7 +684,18 @@
                    {
                        if (returnRecords.Count() == returnRecords.Count(x => x.ReturnStatus == 1))
                        {
                            inboundOrder.ReturnToMESStatus = 1;
                            if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                            {
                                inboundOrder.ReturnToMESStatus = 1;
                            }
                            else if(inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                            {
                                inboundOrder.ReturnToMESStatus = 3;
                            }
                            else
                            {
                                inboundOrder.ReturnToMESStatus = 0;
                            }
                        }
                        else if (returnRecords.Count(x => x.ReturnStatus == 2) > 0)
                        {
@@ -599,14 +706,30 @@
                            inboundOrder.ReturnToMESStatus = 2;
                        }
                        _inboundOrderRepository.UpdateData(inboundOrder);
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,失败数据回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                    }
                    var response = responseModel(inboundOrder, 3, feedmodel);
                    if (response != null && response.IsSuccess)
                    if (response != null && response.IsSuccess && response.Data.Code == "200")
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                        .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        if(inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else if(inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3})
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 0 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
                        {
@@ -617,6 +740,22 @@
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
                         .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else if (inboundOrder.OrderStatus == InOrderStatusEnum.入库中.ObjToInt())
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        else
                        {
                            _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 0 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                        }
                        return content.Error("回传MES失败");
                    }
                }