| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | |
| | | private readonly IRepository<Dt_OutboundOrder> _outboundOrderRepository; |
| | | private readonly IBasicService _basicService; |
| | | private readonly IRepository<Dt_AllocateOrder> _allocateRepository; |
| | | private readonly IRepository<Dt_MaterialCodeInfo> _materialCodeInfoRepository; |
| | | |
| | | public FeedbackMesService(IRepository<Dt_MesReturnRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, HttpClientHelper httpClientHelper, IRepository<Dt_OutboundOrder> outboundOrderRepository, IBasicService basicService, IRepository<Dt_AllocateOrder> allocateRepository) : base(BaseDal) |
| | | public FeedbackMesService(IRepository<Dt_MesReturnRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, HttpClientHelper httpClientHelper, IRepository<Dt_OutboundOrder> outboundOrderRepository, IBasicService basicService, IRepository<Dt_AllocateOrder> allocateRepository, IRepository<Dt_MaterialCodeInfo> materialCodeInfoRepository) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _httpClientHelper = httpClientHelper; |
| | | _outboundOrderRepository = outboundOrderRepository; |
| | | _basicService = basicService; |
| | | _allocateRepository = allocateRepository; |
| | | _materialCodeInfoRepository = materialCodeInfoRepository; |
| | | } |
| | | |
| | | public WebResponseContent OutboundFeedback(string orderNo) |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏋勫缓鍥炶皟瀵硅薄澶辫触"); |
| | | } |
| | | string apiUrl = ""; |
| | | string apiUrl = AppSettings.GetValue("MaterialOutboundFeedbackUrl"); |
| | | returnDTO.ReqCode = reqCode; |
| | | returnDTO.ReqTime = reqTime; |
| | | requestData = returnDTO.Serialize(); |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏋勫缓鍥炶皟瀵硅薄澶辫触"); |
| | | } |
| | | string apiUrl = ""; |
| | | string apiUrl = AppSettings.GetValue("AllocationFeedbackUrl"); ; |
| | | returnDTO.ReqCode = reqCode; |
| | | returnDTO.ReqTime = reqTime; |
| | | requestData = returnDTO.Serialize(); |
| | |
| | | httpResponseResult.ApiUrl = apiUrl; |
| | | } |
| | | |
| | | bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data != null && httpResponseResult.Data.Code == "200"; |
| | | bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200"; |
| | | string message = "鎴愬姛"; |
| | | if (!isSuccess) |
| | | { |
| | |
| | | { |
| | | message = $"MES鎺ュ彛杩斿洖閿欒锛孒TTP浠g爜锛歿httpResponseResult.StatusCode}锛屼俊鎭細{httpResponseResult.ErrorMessage}"; |
| | | } |
| | | else if (httpResponseResult.Data.Code != "200") |
| | | else if (httpResponseResult?.Data?.Code != "200") |
| | | { |
| | | message = $"璋冪敤MES鎺ュ彛澶辫触锛屼唬鐮侊細{httpResponseResult.Data.Code}锛屼俊鎭細{httpResponseResult.Data.Message}"; |
| | | message = $"璋冪敤MES鎺ュ彛澶辫触锛屼唬鐮侊細{httpResponseResult?.Data?.Code}锛屼俊鎭細{httpResponseResult?.Data?.Message}"; |
| | | } |
| | | } |
| | | |
| | | Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord() |
| | | { |
| | | ApiUrl = httpResponseResult.ApiUrl, |
| | | InterfaceType = 1, |
| | | InterfaceType = outboundOrder.OrderType == 0 ? 1 : 3, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderType = outboundOrder.OrderType, |
| | | RequestCode = reqCode, |
| | | RequestData = requestData, |
| | | FailureReason = message, |
| | |
| | | x.ReturnJsonData = ""; |
| | | }); |
| | | |
| | | mesReturnRecord.ReturnType = outboundOrder.Details.Count == outboundOrderDetails.Count ? 1 : 2; |
| | | |
| | | if (outboundOrder.Details.Count == outboundOrderDetails.Count && outboundOrderDetails.All(x => x.ReturnToMESStatus == 1 || x.ReturnToMESStatus == 2)) |
| | | { |
| | | outboundOrder.ReturnToMESStatus = isSuccess ? 1 : 2; |
| | | } |
| | | else |
| | | { |
| | | outboundOrder.ReturnToMESStatus = isSuccess ? 3 : 4; |
| | | } |
| | | |
| | | _outboundOrderRepository.Db.Updateable(outboundOrderDetails).ExecuteCommand(); |
| | | _outboundOrderRepository.UpdateData(outboundOrder); |
| | | } |
| | | |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | WebResponseContent responseContent = new WebResponseContent(); |
| | |
| | | responseContent.Message = message; |
| | | return responseContent; |
| | | } |
| | | catch(Exception ex) |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | |
| | | InterfaceType = 1, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderType = outboundOrder.OrderType, |
| | | RequestCode = returnDTO.ReqCode, |
| | | RequestData = returnDTO.Serialize(), |
| | | FailureReason = message, |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent BarcodeFeedback(string newBarcode) |
| | | { |
| | | try |
| | | { |
| | | Dt_MaterialCodeInfo materialCodeInfo = _materialCodeInfoRepository.QueryFirst(x => x.NewBarcode == newBarcode, new Dictionary<string, OrderByType> { { nameof(Dt_MaterialCodeInfo.Id), OrderByType.Desc } }); |
| | | if (materialCodeInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒扮墿鏂欐潯鐮佷俊鎭瘂newBarcode}"); |
| | | } |
| | | |
| | | string apiUrl = AppSettings.GetValue("BarcodeFeedbackUrl"); |
| | | |
| | | BarcodeReturnDTO returnDTO = new BarcodeReturnDTO() |
| | | { |
| | | BatchNo = materialCodeInfo.BatchNo, |
| | | FactoryArea = materialCodeInfo.FactoryArea, |
| | | OperationType = 1, |
| | | MaterialCode = materialCodeInfo.MaterialCode, |
| | | NewmaterialCode = materialCodeInfo.NewBarcode, |
| | | OldmaterialCode = materialCodeInfo.OldBarcode, |
| | | Operator = materialCodeInfo.Creater, |
| | | Qty = materialCodeInfo.AfterQuantity, |
| | | SupplyCode = materialCodeInfo.SuplierCode, |
| | | Unit = materialCodeInfo.Unit, |
| | | WarehouseCode = materialCodeInfo.WarehouseCode, |
| | | OldQty = materialCodeInfo.OriginalQuantity |
| | | }; |
| | | |
| | | string reqCode = Guid.NewGuid().ToString(); |
| | | string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | string requestData = returnDTO.Serialize(); |
| | | |
| | | HttpResponseResult<MesResponseDTO> httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData); |
| | | httpResponseResult.ApiUrl = apiUrl; |
| | | |
| | | bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200"; |
| | | string message = "鎴愬姛"; |
| | | if (!isSuccess) |
| | | { |
| | | if (!httpResponseResult.IsSuccess) |
| | | { |
| | | message = $"MES鎺ュ彛杩斿洖閿欒锛孒TTP浠g爜锛歿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 = materialCodeInfo.OrderId ?? 0, |
| | | OrderNo = materialCodeInfo.OrderNo ?? "", |
| | | 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(); |
| | | materialCodeInfo.ReturnStatus = httpResponseResult.IsSuccess ? 1 : 2; |
| | | _materialCodeInfoRepository.UpdateData(materialCodeInfo); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | WebResponseContent responseContent = new WebResponseContent(); |
| | | responseContent.Status = isSuccess; |
| | | responseContent.Message = message; |
| | | return responseContent; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |