1
647556386
2025-12-18 3b3ff1836b8837ffd541cc7eefde8d5e5d195110
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/MESOperation/FeedbackMesService.cs
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SqlSugar;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
@@ -25,14 +26,16 @@
        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)
@@ -105,7 +108,6 @@
                    InterfaceType = 1,
                    OrderId = outboundOrder.Id,
                    OrderNo = outboundOrder.OrderNo,
                    OrderType = outboundOrder.OrderType,
                    RequestCode = reqCode,
                    RequestData = requestData,
                    FailureReason = message,
@@ -140,7 +142,7 @@
                    _outboundOrderRepository.Db.Updateable(outboundOrderDetails).ExecuteCommand();
                }
                _unitOfWorkManage.CommitTran();
                WebResponseContent responseContent = new WebResponseContent();
@@ -148,7 +150,7 @@
                responseContent.Message = message;
                return responseContent;
            }
            catch(Exception ex)
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
@@ -234,7 +236,6 @@
                        InterfaceType = 1,
                        OrderId = outboundOrder.Id,
                        OrderNo = outboundOrder.OrderNo,
                        OrderType = outboundOrder.OrderType,
                        RequestCode = returnDTO.ReqCode,
                        RequestData = returnDTO.Serialize(),
                        FailureReason = message,
@@ -329,5 +330,90 @@
                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 = "";
                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 != null && 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);
            }
        }
    }
}