| | |
| | | using System; |
| | | using LogLibrary.Log; |
| | | using MailKit; |
| | | using MailKit.Search; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using Org.BouncyCastle.Asn1.X509; |
| | | using SixLabors.ImageSharp; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.AllocateEnum; |
| | | 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.Util; |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_DTO.Allocate; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.ReturnMES; |
| | | 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; } |
| | | |
| | | public InboundService(IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService) |
| | | 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; |
| | | private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfo; |
| | | private readonly HttpClientHelper _httpClientHelper; |
| | | private readonly IRepository<Dt_MesReturnRecord> _mesReturnRecord; |
| | | 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) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | InboundOrderDetailService = inboundOrderDetailService; |
| | | InbounOrderService = inbounOrderService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | _locationTypeRepository = locationTypeRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _inboundOrderDetailRepository = inboundOrderDetailRepository; |
| | | _stockService = stockService; |
| | | _taskRepository = taskRepository; |
| | | _allocateMaterialInfo = allocateMaterialInfo; |
| | | _httpClientHelper = httpClientHelper; |
| | | _mesReturnRecord = mesReturnRecord; |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | var datevaliDate = _inboundOrderRepository.Db.Queryable<Dt_MaterialExpirationDate>().Where(x=>x.MaterialCode.Contains(item.MaterielCode.Substring(0,6))).First(); |
| | | |
| | | stockInfo.Details.Add(new Dt_StockInfoDetail |
| | | { |
| | | StockId = stockInfo == null ? 0 : stockInfo.Id, |
| | | Barcode = item.Barcode, |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielName = item.MaterielName, |
| | | 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, |
| | | ValidDate = inboundOrder.BusinessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä».ToString() ? item.ValidDate : datevaliDate == null ? null : Convert.ToDateTime(DateTime.Now).AddDays(Convert.ToDouble(datevaliDate.ValidityDays)), |
| | | //ValidDate = datevaliDate == null ? null : DateTime.Now.AddDays(datevaliDate.ValidityDays), |
| | | }); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | public async Task<WebResponseContent> AllcatedGroupPallet(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_StockInfo? stockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletDto.PalletCode).FirstAsync(); |
| | | |
| | | if (_taskRepository.QueryFirst(x => x.PalletCode == palletDto.PalletCode) != null) |
| | | { |
| | | return content.Error($"该æçå·²çæä»»å¡"); |
| | | } |
| | | if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != (int)StockStatusEmun.ç»çæå) |
| | | { |
| | | return content.Error("已䏿¶çæçä¸è½å次ç»ç"); |
| | | } |
| | | |
| | | if (_stockService.StockInfoDetailService.ExistBarcodes(palletDto.Barcode)) |
| | | { |
| | | return content.Error($"{palletDto.Barcode} æ¡ç å¨åºåä¸å·²åå¨"); |
| | | } |
| | | |
| | | 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}ä¸ä¸è´ï¼ä¸å
许ç»ç"); |
| | | } |
| | | Dt_AllocateMaterialInfo allocateMaterialInfo = _allocateMaterialInfo.QueryFirst(x => x.Barcode == palletDto.Barcode); |
| | | if(allocateMaterialInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°è¯¥æ¡ç {palletDto.Barcode}éè°å
¥æºä»çä¿¡æ¯"); |
| | | } |
| | | |
| | | stockInfo.Details.Add(new Dt_StockInfoDetail |
| | | { |
| | | StockId = stockInfo == null ? 0 : stockInfo.Id, |
| | | Barcode = allocateMaterialInfo.Barcode, |
| | | MaterielCode = allocateMaterialInfo.MaterialCode, |
| | | BatchNo = allocateMaterialInfo.BatchNo, |
| | | Unit = allocateMaterialInfo.Unit, |
| | | SupplyCode = allocateMaterialInfo.SupplyCode, |
| | | WarehouseCode = palletDto.WarehouseType, |
| | | StockQuantity = allocateMaterialInfo.Quantity, |
| | | BarcodeQty = allocateMaterialInfo.Quantity, |
| | | BarcodeUnit = allocateMaterialInfo.Unit, |
| | | FactoryArea = allocateMaterialInfo.FactoryArea, |
| | | Status = 0, |
| | | OrderNo = allocateMaterialInfo.OrderNo, |
| | | BusinessType = "1", |
| | | |
| | | }); |
| | | |
| | | if (stockInfo.Id == 0) |
| | | { |
| | | stockInfo.PalletCode = palletDto.PalletCode; |
| | | stockInfo.StockStatus = (int)StockStatusEmun.æºä»å
¥æºä»ç»çæå; |
| | | } |
| | | stockInfo.PalletType = (int)PalletTypeEnum.None; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stockService.StockInfoService.AddMaterielGroup(stockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | 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)); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | LogFactory.GetLog($"ç»çä¿¡æ¯").Info(true, $"ãå¼å¸¸ãï¼ã{ex.Message}ã{Environment.NewLine}ã{ex.StackTrace}ã{Environment.NewLine}{Environment.NewLine}"); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <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); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent BatchInOrderFeedbackToMes(int id) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>() |
| | | .Where(x => x.Id == id) |
| | | .First(); |
| | | |
| | | List<Dt_MesReturnRecord> returnRecords = _mesReturnRecord.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo && x.OrderId == inboundOrder.Id && x.ReturnStatus == 2); |
| | | foreach (var item in returnRecords) |
| | | { |
| | | HttpResponseResult<MesResponseDTO> httpResponse = _httpClientHelper.Post<MesResponseDTO>(item.ApiUrl, item.RequestData); |
| | | item.ReturnCount += 1; |
| | | bool success = httpResponse.IsSuccess && httpResponse.Data.Code == "200"; |
| | | item.ReturnStatus = success ? 1 : 2; |
| | | item.HttpStatusCode = httpResponse.StatusCode.ObjToInt(); |
| | | item.LastReturnTime = DateTime.Now; |
| | | item.ResponseData = httpResponse.Content; |
| | | item.SuccessTime = httpResponse.IsSuccess ? DateTime.Now : null; |
| | | |
| | | //List<Dt_InboundOrderDetail> details=new List<Dt_InboundOrderDetail>(); |
| | | //foreach (var y in item.DetailsId.Split(',')) |
| | | //{ |
| | | // details.Add( _inboundOrderDetailRepository.QueryFirst(x => x.Id == Convert.ToInt32(y))); |
| | | //} |
| | | } |
| | | _mesReturnRecord.UpdateData(returnRecords); |
| | | |
| | | var inboundOrderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus==(int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0) |
| | | .ToList(); |
| | | |
| | | var stocks = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == 6) |
| | | .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo).Any()) |
| | | .ToList(); |
| | | |
| | | var stockIds = stocks.Select(s => s.Id).ToList(); |
| | | |
| | | var allDetailsData = _stockInfoRepository.Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => stockIds.Contains(x.StockId)) |
| | | .ToList(); |
| | | |
| | | var matchedData = inboundOrderDetail |
| | | .Join(allDetailsData, |
| | | inbound => inbound.Barcode, |
| | | stockdetail => stockdetail.Barcode, |
| | | (inbound, stockdetail) => inbound.Barcode) |
| | | .ToList(); |
| | | |
| | | var inbounddetailID = inboundOrderDetail |
| | | .Join(allDetailsData, |
| | | inbound => inbound.Barcode, |
| | | stockdetail => stockdetail.Barcode, |
| | | (inbound, stockdetail) => inbound.Id) |
| | | .ToList(); |
| | | |
| | | var detail = allDetailsData.Where(x => matchedData.Contains(x.Barcode)).ToList(); |
| | | |
| | | if (inboundOrder.OrderType == (int)InOrderTypeEnum.AllocatInbound)//è°æ¨å
¥åº |
| | | { |
| | | var allocate = _inboundOrderRepository.Db.Queryable<Dt_AllocateOrder>().Where(x => x.OrderNo == inboundOrder.InboundOrderNo).First(); |
| | | var allocatefeedmodel = new AllocateDto |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString(), |
| | | ReqTime = DateTime.Now.ToString(), |
| | | BusinessType = "3", |
| | | FactoryArea = inboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | OrderNo = inboundOrder.UpperOrderNo, |
| | | fromWarehouse = allocate?.FromWarehouse ?? "", |
| | | toWarehouse = allocate?.ToWarehouse ?? "", |
| | | Details = GetAllocateDtoDetails(detail) |
| | | }; |
| | | |
| | | if (allocatefeedmodel.Details.Count <= 0) |
| | | { |
| | | throw new Exception("æªæ¾å°éè¦åä¼ çæ°æ®"); |
| | | } |
| | | |
| | | var response = responseModel(inboundOrder, 3, null, allocatefeedmodel); |
| | | |
| | | if (response != null && response.IsSuccess) |
| | | { |
| | | _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id && inbounddetailID.Contains(it.Id)).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 }) |
| | | .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand(); |
| | | return content.Error("åä¼ MES失败"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var feedmodel = new FeedbackInboundRequestModel |
| | | { |
| | | reqCode = Guid.NewGuid().ToString(), |
| | | reqTime = DateTime.Now.ToString(), |
| | | business_type = inboundOrder.BusinessType, |
| | | factoryArea = inboundOrder.FactoryArea, |
| | | operationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | orderNo = inboundOrder.UpperOrderNo, |
| | | status = inboundOrder.OrderStatus, |
| | | details = FeedbackInboundDetailsModelDto(detail) |
| | | }; |
| | | |
| | | if (feedmodel.details.Count<=0) |
| | | { |
| | | throw new Exception("æªæ¾å°éè¦åä¼ çæ°æ®"); |
| | | } |
| | | var response = responseModel(inboundOrder, 3, feedmodel); |
| | | |
| | | if (response != null && response.IsSuccess) |
| | | { |
| | | _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 }) |
| | | .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand(); |
| | | return content.Error("åä¼ MES失败"); |
| | | } |
| | | } |
| | | |
| | | return content.OK("åä¼ MESæå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public List<AllocateDtoDetail> GetAllocateDtoDetails(List<Dt_StockInfoDetail> stockInfoDetails) |
| | | { |
| | | var groupedData = stockInfoDetails.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new AllocateDtoDetail |
| | | { |
| | | MaterialCode = group.Key.MaterielCode, |
| | | LineNo = group.Key.InboundOrderRowNo, |
| | | WarehouseCode = group.Key.WarehouseCode, |
| | | Qty = group.Sum(x => x.BarcodeQty), |
| | | Unit = group.Key.BarcodeUnit, |
| | | Barcodes = group.Select(row => new BarcodeInfo |
| | | { |
| | | Barcode = row.Barcode, |
| | | Qty = row.BarcodeQty, |
| | | BatchNo = row.BatchNo, |
| | | SupplyCode = row.SupplyCode, |
| | | Unit = row.BarcodeUnit |
| | | }).ToList() |
| | | }).ToList(); |
| | | return groupedData; |
| | | } |
| | | public List<FeedbackInboundDetailsModel> FeedbackInboundDetailsModelDto(List<Dt_StockInfoDetail> stockInfoDetails) |
| | | { |
| | | var groupedData = stockInfoDetails.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackInboundDetailsModel |
| | | { |
| | | materialCode = group.Key.MaterielCode, |
| | | lineNo = group.Key.InboundOrderRowNo, |
| | | warehouseCode = group.Key.WarehouseCode, |
| | | qty = group.Sum(x => x.BarcodeQty), |
| | | unit = group.Key.BarcodeUnit, |
| | | barcodes = group.Select(row => new FeedbackBarcodesModel |
| | | { |
| | | barcode = row.Barcode, |
| | | qty = row.BarcodeQty |
| | | }).ToList() |
| | | }).ToList(); |
| | | return groupedData; |
| | | } |
| | | |
| | | public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null) |
| | | { |
| | | HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>(); |
| | | string reqCode = Guid.NewGuid().ToString(); |
| | | string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | string requestData = string.Empty; |
| | | string apiUrl = string.Empty; |
| | | if (model != null) |
| | | { |
| | | apiUrl = AppSettings.GetValue("AldMaterialWarehousing"); |
| | | httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, model.Serialize()); |
| | | requestData = model.Serialize(); |
| | | } |
| | | else |
| | | { |
| | | apiUrl = AppSettings.GetValue("AldAllocationOperation"); |
| | | httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, allocateDto.Serialize()); |
| | | requestData = allocateDto.Serialize(); |
| | | } |
| | | httpResponseResult.ApiUrl = apiUrl; |
| | | bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200"; |
| | | string message = "æå"; |
| | | if (!isSuccess) |
| | | { |
| | | if (!httpResponseResult.IsSuccess) |
| | | { |
| | | message = $"MESæ¥å£è¿åé误ï¼HTTP代ç ï¼{httpResponseResult.StatusCode}ï¼ä¿¡æ¯ï¼{httpResponseResult.ErrorMessage}"; |
| | | } |
| | | else if (httpResponseResult?.Data?.Code != "200") |
| | | { |
| | | message = $"è°ç¨MESæ¥å£å¤±è´¥ï¼ä»£ç ï¼{httpResponseResult?.Data?.Code}ï¼ä¿¡æ¯ï¼{httpResponseResult?.Data?.Message}"; |
| | | } |
| | | } |
| | | Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord() |
| | | { |
| | | ApiUrl = httpResponseResult.ApiUrl, |
| | | InterfaceType = InterfaceType, |
| | | OrderId = order.Id, |
| | | OrderNo = order.InboundOrderNo, |
| | | RequestCode = reqCode, |
| | | RequestData = requestData, |
| | | FailureReason = message, |
| | | LastReturnTime = DateTime.Now, |
| | | HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(), |
| | | ResponseData = httpResponseResult.Content, |
| | | ReturnType = 0, |
| | | ReturnCount = 1, |
| | | ReturnStatus = httpResponseResult.IsSuccess ? 1 : 2, |
| | | SuccessTime = httpResponseResult.IsSuccess ? DateTime.Now : null |
| | | }; |
| | | _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand(); |
| | | |
| | | return httpResponseResult; |
| | | } |
| | | } |
| | | } |