using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Common.MaterielEnum; using WIDESEA_Core; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_DTO.MES; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_IOutboundRepository; using WIDESEA_IOutboundService; using WIDESEA_IRecordService; using WIDESEA_IStockService; using WIDESEA_Model.Models; namespace WIDESEA_OutboundService { public class OutMESOrderService : ServiceBase, IOutMESOrderService { public IOutMESOrderRepository Repository => BaseDal; private IBasicRepository _basicRepository; private IStockService _stockService; private IOutStockLockInfoService _outStockLockInfoService; private IBasicService _basicService; private ILocationStatusChangeRecordService _locationStatusChangeRecordService; private readonly IMapper _mapper; public OutMESOrderService(IOutMESOrderRepository BaseDal,IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService,IMapper mapper) : base(BaseDal) { _basicRepository = basicRepository; _stockService = stockService; _outStockLockInfoService = outStockLockInfoService; _basicService = basicService; _locationStatusChangeRecordService = locationStatusChangeRecordService; _mapper = mapper; } /// /// 接收MES领料计划 /// /// public WebResponseContent ReceiveOutBound(OutMESOrderDTO outMESOrderDTO) { WebResponseContent content = new WebResponseContent(); try { if (outMESOrderDTO==null) { return content.Error("领料计划传入信息为空"); } if (outMESOrderDTO.OutDetailId <= 0) { return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}需要大于0"); } if (outMESOrderDTO.ReqQuantity <= 0) { return content.Error($"领料计划{nameof(OutMESOrderDTO.ReqQuantity)}:{outMESOrderDTO.ReqQuantity}需要大于0"); } //获取所有物料信息 List materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x=>x.MaterielInvOrgId==MaterielInvOrgEnum.新厂.ObjToInt()); //获取所有临料计划 List outMESOrders = BaseDal.QueryData(); Dt_MaterielInfo? ExistmaterielInfo = materielInfos.FirstOrDefault(x=>x.MaterielCode== outMESOrderDTO.MaterialCode); if (ExistmaterielInfo == null) { return content.Error($"物料编码{nameof(OutMESOrderDTO.MaterialCode)}:{outMESOrderDTO.MaterialCode}信息不存在"); } Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=>x.OutDetailId==outMESOrderDTO.OutDetailId); if (OldoutMESOrder!=null) { return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}信息已存在"); } return content.Error($"领料计划{nameof(OutMESOrderDTO.ProductOrderNo)}:{outMESOrderDTO.ProductOrderNo},物料{outMESOrderDTO.MaterialCode}无可分配库存"); Dt_OutMESOrder outMESOrder = _mapper.Map(outMESOrderDTO); BaseDal.AddData(outMESOrder); return content.OK("接收成功"); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }