| using AutoMapper; | 
| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
| using WIDESEA_Common.OrderEnum; | 
| using WIDESEA_Common.WareHouseEnum; | 
| using WIDESEA_Core; | 
| using WIDESEA_Core.BaseRepository; | 
| using WIDESEA_Core.BaseServices; | 
| using WIDESEA_Core.Helper; | 
| using WIDESEA_DTO.ERP; | 
| using WIDESEA_IBasicRepository; | 
| using WIDESEA_IInboundRepository; | 
| using WIDESEA_IInboundService; | 
| using WIDESEA_Model.Models; | 
|   | 
| namespace WIDESEA_InboundService | 
| { | 
|     public class ErpProInOrderService : ServiceBase<Dt_ErpProInOrder, IErpProInOrderRepository>, IErpProInOrderService | 
|     { | 
|         public IErpProInOrderRepository Repository => BaseDal; | 
|         private readonly IUnitOfWorkManage _unitOfWorkManage; | 
|         private IBasicRepository _basicRepository; | 
|         private readonly IMapper _mapper; | 
|         public ErpProInOrderService(IErpProInOrderRepository BaseDal, IUnitOfWorkManage unitOfWorkManag, IBasicRepository basicRepository,IMapper mapper) : base(BaseDal) | 
|         { | 
|             _unitOfWorkManage = unitOfWorkManag; | 
|             _basicRepository = basicRepository; | 
|             _mapper = mapper; | 
|         } | 
|         /// <summary> | 
|         /// 接收成品调入销售单据 | 
|         /// </summary> | 
|         public WebResponseContent ProductWarehousingOrder(ErpProductWarehousingOrderDTO warehousingOrderDTO) | 
|         { | 
|             WebResponseContent content = new WebResponseContent(); | 
|             try | 
|             { | 
|                 //判断单据是否已存在 | 
|                 Dt_ErpProInOrder erpProInOrderOld = BaseDal.QueryFirst(x => x.UpperOrderNo == warehousingOrderDTO.TransferNo); | 
|                 if ( erpProInOrderOld != null ) | 
|                 { | 
|                     return content.Error($"单据{warehousingOrderDTO.TransferNo}已存在"); | 
|                 } | 
|                 //判断所传客户是否存在 | 
|                 Dt_CustomerInfo customerInfo = _basicRepository.CustomerInfoRepository.QueryFirst(x=>x.Code==warehousingOrderDTO.Customer); | 
|                 if ( customerInfo == null ) | 
|                 { | 
|                     return content.Error($"客户{warehousingOrderDTO.Customer}信息不存在"); | 
|                 } | 
|                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); | 
|                 ErpProOrderTypeEnum orderTypeEnum = new ErpProOrderTypeEnum(); | 
|                 if (warehousingOrderDTO.TransferNo.Substring(0, 3)=="DBD") | 
|                 { | 
|                     orderTypeEnum = ErpProOrderTypeEnum.ProAllocat; | 
|                 } | 
|                 else | 
|                 { | 
|                     orderTypeEnum = ErpProOrderTypeEnum.ProConsign; | 
|                 } | 
|                 Dt_ErpProInOrder erpProInOrder = _mapper.Map<Dt_ErpProInOrder>(warehousingOrderDTO); | 
|                 erpProInOrder.OrderType = orderTypeEnum.ObjToInt(); | 
|                 erpProInOrder.WarehouseId = warehouse.WarehouseId; | 
|                 BaseDal.AddData(erpProInOrder); | 
|                 content.OK(); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 content.Error(ex.Message); | 
|             } | 
|             return content; | 
|         } | 
|     } | 
| } |