| | |
| | | using System; |
| | | using LogLibrary.Log; |
| | | using MailKit; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_IInboundService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | |
| | | namespace WIDESEA_InboundService |
| | | { |
| | | public class InboundService : IInboundService |
| | | { |
| | | LogFactory LogFactory = new LogFactory(); |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | public IInboundOrderDetailService InboundOrderDetailService { get; } |
| | | |
| | | public IInboundOrderService InbounOrderService { get; } |
| | | private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository; |
| | | private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository; |
| | | private readonly IRepository<Dt_LocationType> _locationTypeRepository; |
| | | private readonly IRepository<Dt_StockInfo> _stockInfoRepository; |
| | | private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository; |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private IStockService _stockService; |
| | | |
| | | public InboundService(IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService) |
| | | 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) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | InboundOrderDetailService = inboundOrderDetailService; |
| | | InbounOrderService = inbounOrderService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | _locationTypeRepository = locationTypeRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _inboundOrderDetailRepository = inboundOrderDetailRepository; |
| | | _stockService = stockService; |
| | | _taskRepository = taskRepository; |
| | | } |
| | | |
| | | public async Task<WebResponseContent> GroupPallet(GroupPalletDto palletDto) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | (bool, string, object?) result2 = ModelValidate.ValidateModelData(palletDto); |
| | | if (!result2.Item1) return content.Error(result2.Item2); |
| | | |
| | | var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == palletDto.WarehouseType).Select(x => x.Code).First(); |
| | | if (string.IsNullOrEmpty(code)) |
| | | { |
| | | return content.Error($"ä»åºä¸æ²¡æè¯¥{palletDto.WarehouseType}ç¼å·ã"); |
| | | } |
| | | |
| | | Dt_InboundOrder inboundOrder = new Dt_InboundOrder(); |
| | | var details = _inboundOrderDetailRepository.QueryData(x => (x.OutBoxbarcodes == palletDto.Barcode|| x.Barcode == palletDto.Barcode) && x.OrderDetailStatus == (int)InOrderStatusEnum.æªå¼å§); |
| | | |
| | | if (details.Count() <= 0) |
| | | { |
| | | return content.Error("æªæ¾å°è¯¥æ¡ç åæ®ä¿¡æ¯è¯·ç¡®è®¤æ¯å¦å·²ç»ç»ç宿"); |
| | | } |
| | | inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Includes(x=>x.Details).Where(x => x.Id == details.First().OrderId).First(); |
| | | |
| | | if (inboundOrder == null) |
| | | { |
| | | return content.Error("æªæ¾å°è¯¥æ¡ç 主åä¿¡æ¯"); |
| | | } |
| | | Dt_StockInfo? stockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletDto.PalletCode).FirstAsync(); |
| | | |
| | | List<string?> materielCodes = details.GroupBy(x => x.Barcode).Select(x => x.Key).ToList(); |
| | | |
| | | (bool, string, object?) result = CheckMaterielGroupParam(palletDto, materielCodes, inboundOrder, stockInfo); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = Convert.ToInt32(palletDto.locationType) }; |
| | | stockInfo.Details = new List<Dt_StockInfoDetail>(); |
| | | } |
| | | |
| | | if (stockInfo != null && stockInfo.Details.Count>0 && stockInfo.Details.FirstOrDefault()?.WarehouseCode != palletDto.WarehouseType) |
| | | { |
| | | return content.Error($"该æçç»çä»åºä¸º{stockInfo.Details.FirstOrDefault()?.WarehouseCode}ä¸å½åä»åº{palletDto.WarehouseType}ä¸ä¸è´ï¼ä¸å
许ç»ç"); |
| | | } |
| | | |
| | | foreach (var item in details) |
| | | { |
| | | stockInfo.Details.Add(new Dt_StockInfoDetail |
| | | { |
| | | StockId = stockInfo == null ? 0 : stockInfo.Id, |
| | | Barcode = item.Barcode, |
| | | MaterielCode = item.MaterielCode, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | InboundOrderRowNo = item.lineNo, |
| | | SupplyCode = item.SupplyCode, |
| | | WarehouseCode = palletDto.WarehouseType, |
| | | StockQuantity = item.OrderQuantity, |
| | | BarcodeQty = item.BarcodeQty, |
| | | BarcodeUnit = item.BarcodeUnit, |
| | | FactoryArea = inboundOrder.FactoryArea, |
| | | Status = 0, |
| | | OrderNo = inboundOrder.InboundOrderNo, |
| | | BusinessType = inboundOrder.BusinessType, |
| | | |
| | | }); |
| | | |
| | | item.ReceiptQuantity = item.BarcodeQty; |
| | | item.OrderDetailStatus = (int)OrderDetailStatusEnum.GroupAndInbound; |
| | | item.WarehouseCode = palletDto.WarehouseType; |
| | | item.ReturnToMESStatus = 0; |
| | | } |
| | | |
| | | if (stockInfo.Id == 0) |
| | | { |
| | | stockInfo.PalletCode = palletDto.PalletCode; |
| | | stockInfo.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | } |
| | | stockInfo.PalletType = (int)PalletTypeEnum.None; |
| | | |
| | | List<int> updateDetailIds = details.Select(x => x.Id).ToList(); |
| | | if (inboundOrder.OrderStatus == (int)InOrderStatusEnum.æªå¼å§) |
| | | { |
| | | inboundOrder.OrderStatus = (int)InOrderStatusEnum.å
¥åºä¸; |
| | | } |
| | | inboundOrder.Operator = App.User.UserName; |
| | | content = MaterielGroupUpdateData(inboundOrder, details, stockInfo).Result; |
| | | if (content.Status) |
| | | { |
| | | Dt_StockInfo? NewstockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletDto.PalletCode).FirstAsync(); |
| | | |
| | | return WebResponseContent.Instance.OK(data: NewstockInfo.Details.OrderByDescending(x => x.Id)); |
| | | } |
| | | else |
| | | { |
| | | content = WebResponseContent.Instance.Error(content.Message); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog($"ç»çä¿¡æ¯").Info(true, $"ãå¼å¸¸ãï¼ã{ex.Message}ã{Environment.NewLine}ã{ex.StackTrace}ã{Environment.NewLine}{Environment.NewLine}"); |
| | | return content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éªè¯ç»çæ°æ® |
| | | /// </summary> |
| | | /// <param name="materielGroupDTO">ç©æç»çDTO</param> |
| | | /// <param name="matSerialNumberDTOs">æ«ç åºåå·</param> |
| | | /// <param name="materielInfos">ç©æä¿¡æ¯</param> |
| | | /// <param name="materielCodes">ç©æç¼å·</param> |
| | | /// <param name="inboundOrder">å
¥åºåæ®</param> |
| | | /// <param name="stockInfo">ç»çä¿¡æ¯</param> |
| | | /// <returns></returns> |
| | | public (bool, string, object?) CheckMaterielGroupParam(GroupPalletDto materielGroupDTO, List<string> barcodeCodes, Dt_InboundOrder inboundOrder, Dt_StockInfo stockInfo) |
| | | { |
| | | (bool, string, object?) result = ModelValidate.ValidateModelData(materielGroupDTO); |
| | | if (!result.Item1) return result; |
| | | |
| | | if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null) |
| | | { |
| | | return (false, "该æçå·å·²æä»»å¡", materielGroupDTO); |
| | | } |
| | | |
| | | if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != (int)StockStatusEmun.ç»çæå) |
| | | { |
| | | return (false, "已䏿¶çæçä¸è½å次ç»ç", materielGroupDTO); |
| | | } |
| | | |
| | | if (_stockService.StockInfoDetailService.ExistBarcodes(barcodeCodes)) |
| | | { |
| | | return (false, $"{barcodeCodes[0]} æ¡ç å¨åºåä¸å·²åå¨", materielGroupDTO); |
| | | } |
| | | |
| | | if (inboundOrder == null) |
| | | { |
| | | return (false, "åæ®ä¸åå¨", materielGroupDTO); |
| | | } |
| | | |
| | | if (inboundOrder.Details == null || inboundOrder.Details.Count == 0) |
| | | { |
| | | return (false, "æ åæ®æç»ä¿¡æ¯", materielGroupDTO); |
| | | } |
| | | |
| | | if (inboundOrder.OrderStatus != (int)InOrderStatusEnum.æªå¼å§ && inboundOrder.OrderStatus != (int)InOrderStatusEnum.å
¥åºä¸) |
| | | { |
| | | return (false, "è¯¥åæ®ä¸å¯åç»ç", materielGroupDTO); |
| | | } |
| | | |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => barcodeCodes.Contains(x.Barcode)).ToList(); |
| | | |
| | | if (inboundOrderDetails.GroupBy(x => x.Barcode).Count() != barcodeCodes.Count) |
| | | { |
| | | return (false, "æç©æä¸å¨åæ®å
", materielGroupDTO); |
| | | } |
| | | |
| | | return (true, "æå", materielGroupDTO); |
| | | } |
| | | |
| | | public async Task<WebResponseContent> MaterielGroupUpdateData(Dt_InboundOrder inboundOrder, List<Dt_InboundOrderDetail> inboundOrderDetails, Dt_StockInfo stockInfo) |
| | | { |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | //await _inboundOrderRepository.Db.UpdateNav(inboundOrder).Include(x=>x.Details).ExecuteCommandAsync(); |
| | | _inboundOrderRepository.UpdateData(inboundOrder); |
| | | _inboundOrderDetailRepository.UpdateData(inboundOrderDetails); |
| | | _stockService.StockInfoService.AddMaterielGroup(stockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |