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; } List GradeCodes = new List { "001" }; /// /// 接收MES领料计划 /// /// public WebResponseContent ReceiveOutBound(List outMESOrderDTOs) { WebResponseContent content = new WebResponseContent(); try { if (outMESOrderDTOs==null || outMESOrderDTOs.Count <= 0) { return content.Error("领料计划传入信息为空"); } outMESOrderDTOs.Select(x => x.OutDetailId); List warehouses = _basicRepository.WarehouseRepository.QueryData(); OutMESOrderDTO? CheckWarehouseCode = outMESOrderDTOs.FirstOrDefault(x => !warehouses.Select(x => x.WarehouseCode).Contains(x.WarehouseCode)); if (CheckWarehouseCode!=null) { return content.Error($"领料计划库区{nameof(OutMESOrderDTO.WarehouseCode)}:{CheckWarehouseCode.WarehouseCode}不存在"); } OutMESOrderDTO? CheckGradeCode = outMESOrderDTOs.FirstOrDefault(x => !GradeCodes.Contains(x.GradeCode)); if (CheckGradeCode != null) { return content.Error($"领料计划库区{nameof(OutMESOrderDTO.GradeCode)}:{CheckGradeCode.GradeCode}不存在"); } OutMESOrderDTO? CheckOutDetailId = outMESOrderDTOs.FirstOrDefault(x => x.OutDetailId <= 0); if (CheckOutDetailId != null) { return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{CheckOutDetailId.ProductOrderNo}需要大于0"); } OutMESOrderDTO? CheckReqQuantity = outMESOrderDTOs.FirstOrDefault(x => x.ReqQuantity <= 0); if (CheckReqQuantity != null) { return content.Error($"领料计划{nameof(OutMESOrderDTO.ReqQuantity)}:{CheckReqQuantity.ProductOrderNo}需要大于0"); } //获取所有物料信息 List materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x=>x.MaterielInvOrgId==MaterielInvOrgEnum.新厂.ObjToInt()); //获取所有领料计划 List outMESOrders = BaseDal.QueryData(); OutMESOrderDTO? CheckMaterialCode = outMESOrderDTOs.FirstOrDefault(x=> !materielInfos.Select(x=>x.MaterielCode).Contains(x.MaterialCode)); if (CheckMaterialCode != null) { return content.Error($"物料编码{nameof(OutMESOrderDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}信息不存在"); } Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=> outMESOrderDTOs.Select(x=>x.OutDetailId).Contains(x.OutDetailId)); if (OldoutMESOrder!=null) { return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{OldoutMESOrder.OutDetailId}信息已存在"); } List outMESOrder = outMESOrderDTOs.Select(x=> _mapper.Map(x)).ToList(); BaseDal.AddData(outMESOrder); return content.OK("接收成功"); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }