| | |
| | | using WIDESEA_DTO.ReturnMES; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_Model.Models; |
| | | using static HslCommunication.Profinet.Knx.KnxCode; |
| | | |
| | | namespace WIDESEA_BasicService.MESOperation |
| | | { |
| | |
| | | private readonly HttpClientHelper _httpClientHelper; |
| | | private readonly IRepository<Dt_OutboundOrder> _outboundOrderRepository; |
| | | private readonly IBasicService _basicService; |
| | | private readonly IRepository<Dt_AllocateOrder> _allocateRepository; |
| | | |
| | | public FeedbackMesService(IRepository<Dt_MesReturnRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, HttpClientHelper httpClientHelper, IRepository<Dt_OutboundOrder> outboundOrderRepository, IBasicService basicService) : base(BaseDal) |
| | | public FeedbackMesService(IRepository<Dt_MesReturnRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, HttpClientHelper httpClientHelper, IRepository<Dt_OutboundOrder> outboundOrderRepository, IBasicService basicService, IRepository<Dt_AllocateOrder> allocateRepository) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _httpClientHelper = httpClientHelper; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | | _basicService = basicService; |
| | | _allocateRepository = allocateRepository; |
| | | } |
| | | |
| | | public void MaterialOutboundFeedback(string orderNo) |
| | | public WebResponseContent OutboundFeedback(string orderNo) |
| | | { |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == orderNo).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) |
| | | { |
| | | // todo è®°å½æ¥å¿ï¼æªæ¾å°å¯¹åºçåºåºå |
| | | |
| | | return; |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçåºåºåä¿¡æ¯"); |
| | | } |
| | | 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; |
| | | List<string> lineNos = new List<string>(); |
| | | if (outboundOrder.OrderType == 0) |
| | | { |
| | | MaterialOutboundReturnDTO? returnDTO = BuildOutboundFeedbackData(outboundOrder); |
| | | if (returnDTO == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æå»ºåè°å¯¹è±¡å¤±è´¥"); |
| | | } |
| | | string apiUrl = ""; |
| | | returnDTO.ReqCode = reqCode; |
| | | returnDTO.ReqTime = reqTime; |
| | | requestData = returnDTO.Serialize(); |
| | | lineNos = returnDTO.Details.Select(x => x.LineNo).ToList(); |
| | | httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData); |
| | | httpResponseResult.ApiUrl = apiUrl; |
| | | } |
| | | else |
| | | { |
| | | Dt_AllocateOrder allocateOrder = _allocateRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçè°æ¨å"); |
| | | } |
| | | AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse); |
| | | if (returnDTO == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æå»ºåè°å¯¹è±¡å¤±è´¥"); |
| | | } |
| | | string apiUrl = ""; |
| | | returnDTO.ReqCode = reqCode; |
| | | returnDTO.ReqTime = reqTime; |
| | | requestData = returnDTO.Serialize(); |
| | | lineNos = returnDTO.Details.Select(x => x.LineNo).ToList(); |
| | | httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData); |
| | | httpResponseResult.ApiUrl = apiUrl; |
| | | } |
| | | |
| | | bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data != null && 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 = 1, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderType = outboundOrder.OrderType, |
| | | 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.BeginTran(); |
| | | _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand(); |
| | | |
| | | if (isSuccess) |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = outboundOrder.Details.Where(x => lineNos.Contains(x.lineNo)).ToList(); |
| | | outboundOrderDetails.ForEach(x => |
| | | { |
| | | if (x.OverOutQuantity == x.OrderQuantity - x.MoveQty) |
| | | { |
| | | x.ReturnToMESStatus = isSuccess ? 1 : 2; |
| | | } |
| | | else |
| | | { |
| | | x.ReturnToMESStatus = isSuccess ? 3 : 4; |
| | | } |
| | | x.CurrentDeliveryQty = 0; |
| | | x.ReturnJsonData = ""; |
| | | }); |
| | | |
| | | _outboundOrderRepository.Db.Updateable(outboundOrderDetails).ExecuteCommand(); |
| | | } |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | WebResponseContent responseContent = new WebResponseContent(); |
| | | responseContent.Status = isSuccess; |
| | | responseContent.Message = message; |
| | | return responseContent; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_OutboundOrderDetail> details = outboundOrder.Details; |
| | | |
| | | List<AllocationDetail> returnDetails = new List<AllocationDetail>(); |
| | | |
| | | foreach (var detail in details) |
| | | { |
| | | List<Barcodes>? barcodes = JsonConvert.DeserializeObject<List<Barcodes>>(detail.ReturnJsonData); |
| | | if (barcodes != null && barcodes.Any()) |
| | | { |
| | | UnitConvertResultDTO currentResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.CurrentDeliveryQty); |
| | | UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.OrderQuantity); |
| | | |
| | | returnDetails.Add(new AllocationDetail |
| | | { |
| | | Barcodes = barcodes, |
| | | BatchNo = detail.BatchNo, |
| | | LineNo = detail.lineNo, |
| | | MaterialCode = detail.MaterielCode, |
| | | Qty = totalResult.ToQuantity, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | Unit = detail.BarcodeUnit |
| | | }); |
| | | } |
| | | } |
| | | |
| | | AllocationReturnDTO outboundReturnDTO = new AllocationReturnDTO() |
| | | { |
| | | Business_type = outboundOrder.BusinessType, |
| | | Details = returnDetails, |
| | | FactoryArea = outboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | FromWarehouse = fromWarehouse, |
| | | ToWarehouse = toWarehouse |
| | | }; |
| | | |
| | | return outboundReturnDTO; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public void MaterialOutboundFeedback(Dt_OutboundOrder outboundOrder) |
| | | { |
| | | try |
| | | { |
| | | MaterialOutboundReturnDTO? returnDTO = BuildOutboundFeedbackData(outboundOrder); |
| | | if (returnDTO != null) |
| | | { |
| | |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | public MaterialOutboundReturnDTO? BuildOutboundFeedbackData(Dt_OutboundOrder outboundOrder) |
| | |
| | | |
| | | foreach (var detail in details) |
| | | { |
| | | List<Barcodes>? barcodes = JsonConvert.DeserializeObject<List<Barcodes>>(detail.ReturnJsonData); |
| | | if (barcodes != null && barcodes.Any()) |
| | | if (!string.IsNullOrWhiteSpace(detail.ReturnJsonData)) |
| | | { |
| | | UnitConvertResultDTO currentResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.CurrentDeliveryQty); |
| | | UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.OrderQuantity); |
| | | |
| | | returnDetails.Add(new MaterialOutboundDetail |
| | | List<Barcodes>? barcodes = JsonConvert.DeserializeObject<List<Barcodes>>(detail.ReturnJsonData); |
| | | if (barcodes != null && barcodes.Any()) |
| | | { |
| | | Barcodes = barcodes, |
| | | CurrentDeliveryQty = currentResult.ToQuantity, |
| | | LineNo = detail.lineNo, |
| | | MaterialCode = detail.MaterielCode, |
| | | Qty = totalResult.ToQuantity, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | Unit = detail.BarcodeUnit |
| | | }); |
| | | UnitConvertResultDTO currentResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.CurrentDeliveryQty); |
| | | UnitConvertResultDTO totalResult = _basicService.UnitQuantityConvert(detail.MaterielCode, detail.Unit, detail.BarcodeUnit, detail.OrderQuantity); |
| | | |
| | | returnDetails.Add(new MaterialOutboundDetail |
| | | { |
| | | Barcodes = barcodes, |
| | | CurrentDeliveryQty = currentResult.ToQuantity, |
| | | LineNo = detail.lineNo, |
| | | MaterialCode = detail.MaterielCode, |
| | | Qty = totalResult.ToQuantity, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | Unit = detail.BarcodeUnit |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |