| | |
| | | using AutoMapper; |
| | | using MailKit.Search; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_External.ERPService; |
| | | using WIDESEA_External.Model; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundRepository; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IStockRepository; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | |
| | |
| | | public class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IBasicService _basicService; |
| | | private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository; |
| | | |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | private readonly IInvokeERPService _invokeERPService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository) : base(BaseDal) |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService, |
| | | IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _basicService = basicService; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _stockInfoService = stockInfoService; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _invokeERPService = invokeERPService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | } |
| | | |
| | | public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model) |
| | |
| | | OrderQuantity = model.Qty, |
| | | OrderId = oldOutboundOrder.Id |
| | | }; |
| | | |
| | | _outboundOrderDetailRepository.AddData(outboundOrderDetail); |
| | | } |
| | | } |
| | |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | OrderQuantity = model.Qty, |
| | | }; |
| | | |
| | | Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder() |
| | | { |
| | | OrderNo=model.OrderNo, |
| | | UpperOrderNo = model.OrderNo, |
| | | OrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(), |
| | | OrderType = OutOrderTypeEnum.Issue.ObjToInt(), |
| | | CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(), |
| | | WarehouseId = warehouse.WarehouseId, |
| | | DepartmentCode = model.DepartmentCode, |
| | | DepartmentName = model.DepartmentName, |
| | | Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail } |
| | | }; |
| | | |
| | | Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | } |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æç»è¡å·ä¿¡æ¯"); |
| | | } |
| | | if(outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) |
| | | if (outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"该æç»ä¸å¯ä¿®æ¹"); |
| | | } |
| | |
| | | |
| | | _outboundOrderDetailRepository.UpdateData(outboundOrderDetail); |
| | | } |
| | | else if (model.Way == 3) |
| | | { |
| | | if (oldOutboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥åºåºå"); |
| | | } |
| | | } |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | //䏿¥åºåºå®æ |
| | | public WebResponseContent TestOutUpload(int id,Dt_StockInfo stockInfo) |
| | | { |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x=>x.Id==id).Includes(x=>x.Details).First(); |
| | | Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == outboundOrder.WarehouseId); |
| | | //æµè¯æ¶åºç»ERP䏿¥åºåºå®æ |
| | | ERPIssueModel issueModel = new ERPIssueModel(); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | if (stockInfo==null) |
| | | { |
| | | stockInfos = TestOutStocksUpdate(warehouse).Data as List<Dt_StockInfo> ?? new List<Dt_StockInfo>(); |
| | | List<ERPPickItemModel> eRPOutPick =new List<ERPPickItemModel>(); |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | { |
| | | Lotno= stockInfos[i].Details[0].BatchNo, |
| | | Qty= stockInfos[i].Details[0].StockQuantity.ObjToInt().ToString(), |
| | | Location= warehouse.WarehouseCode |
| | | }; |
| | | eRPOutPick.Add(pickItemModel); |
| | | } |
| | | |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | Rowindex = outboundOrder.Details[0].RowNo, |
| | | Material = outboundOrder.Details[0].MaterielCode, |
| | | Qty = (outboundOrder.Details[0].OrderQuantity.ObjToInt()).ToString(), |
| | | Dataitem = eRPOutPick |
| | | }; |
| | | |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = new List<ERPPickModel>() { pickModel } |
| | | }; |
| | | issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = id.ToString(), |
| | | Code = outboundOrder.OrderNo,//æµè¯ |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = outboundOrder.Creater, |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | Dt_OutboundOrderDetail orderDetail = outboundOrder.Details.FirstOrDefault(x => x.MaterielCode == stockInfo.Details[0].MaterielCode); |
| | | |
| | | ERPPickItemModel pickItemModel = new ERPPickItemModel() |
| | | { |
| | | Lotno = stockInfo.Details[0].BatchNo, |
| | | Qty = stockInfo.Details[0].StockQuantity.ObjToInt().ToString(), |
| | | Location = stockInfo.LocationCode |
| | | }; |
| | | ERPPickModel pickModel = new ERPPickModel() |
| | | { |
| | | Rowindex = outboundOrder.Details[0].RowNo, |
| | | Material = outboundOrder.Details[0].MaterielCode, |
| | | Qty = (outboundOrder.Details[0].OrderQuantity.ObjToInt()).ToString(), |
| | | Dataitem = new List<ERPPickItemModel> { pickItemModel } |
| | | }; |
| | | ERPIssueItemModel issueItemModel = new ERPIssueItemModel() |
| | | { |
| | | Pickcode = outboundOrder.UpperOrderNo, |
| | | PickList = new List<ERPPickModel>() { pickModel } |
| | | }; |
| | | issueModel = new ERPIssueModel() |
| | | { |
| | | UniqueTag = id.ToString(), |
| | | Code = outboundOrder.OrderNo,//æµè¯ |
| | | WarehouseCode = warehouse.WarehouseCode, |
| | | Docremark = "", |
| | | Deptno = outboundOrder.DepartmentCode, |
| | | Deptname = outboundOrder.DepartmentName, |
| | | Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | Createuser = outboundOrder.Creater, |
| | | Issitem = new List<ERPIssueItemModel>() { issueItemModel }, |
| | | }; |
| | | } |
| | | |
| | | string response = _invokeERPService.InvokeOutStandardsApi(issueModel); |
| | | ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>(); |
| | | if (requestContent.res == 1) |
| | | { |
| | | if (stockInfos.Count>0) |
| | | { |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | } |
| | | return WebResponseContent.Instance.OK(requestContent.Data); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error(requestContent.Data); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ¹åºåºååºåç¶æ |
| | | /// </summary> |
| | | /// <param name="warehouse"></param> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse) |
| | | { |
| | | try |
| | | { |
| | | //è·ååºåºååºå |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).ToList(); |
| | | if (stockInfos.Count<=0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"åºåä¸è¶³"); |
| | | } |
| | | //æ´æ¹ç¶æ |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | }); |
| | | return WebResponseContent.Instance.OK("æå", stockInfos); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |