public List<com.Sconit.Entity.SAP.ORD.OrderDetail> GetProcOrders(string flow, string supplier, string item, string plant) { if (string.IsNullOrWhiteSpace(supplier)) { if (!string.IsNullOrWhiteSpace(flow)) { supplier = this.genericMgr.FindAllWithNativeSql<string>("select PartyFrom from SCM_FlowMstr where Code = ? and [Type] = ?", new object[] { flow, CodeMaster.OrderType.Procurement }).SingleOrDefault(); if (string.IsNullOrWhiteSpace(supplier)) { throw new BusinessException("采购路线{0}不存在。", flow); } } else if (string.IsNullOrWhiteSpace(item)) { throw new TechnicalException("采购路线、供应商和物料代码不能全部为空。"); } } ZSEKPTH[] headOut = null; ZSEKPTI[] detailOut = null; lock (GetProcOrdersLock) { try { #region 获取SAP计划协议 log.Debug("开始连接Web服务获取计划协议,工厂" + plant + (string.IsNullOrWhiteSpace(supplier) ? ", 供应商: " + supplier : "") + (string.IsNullOrWhiteSpace(item) ? ", 物料号: " + item : "")); MI_SL_OUTService slOutService = new MI_SL_OUTService(); slOutService.Credentials = base.Credentials; slOutService.Timeout = base.TimeOut; slOutService.Url = ReplaceSAPServiceUrl(slOutService.Url); ZSDELIVERY deliveryIn = new ZSDELIVERY(); deliveryIn.LIFNR = supplier; deliveryIn.WERKS = plant; deliveryIn.MATNR = item; headOut = slOutService.MI_SL_OUT(deliveryIn, out detailOut); log.Debug("连接Web服务获取计划协议完成,工厂" + plant + (string.IsNullOrWhiteSpace(supplier) ? ", 供应商: " + supplier : "") + (string.IsNullOrWhiteSpace(item) ? ", 物料号: " + item : "")); #endregion } catch (Exception ex) { log.Error("服务获取计划协议完成出现异常,工厂" + plant + (string.IsNullOrWhiteSpace(supplier) ? ", 供应商: " + supplier : "") + (string.IsNullOrWhiteSpace(item) ? ", 物料号: " + item : "") + ",异常信息:" + ex.Message, ex); throw new BusinessException("从SAP获取计划协议出现异常,异常信息:{0}", ex.Message); } } return ProcessPoOut(flow, supplier, item, plant, headOut, detailOut); }
//根据sap计划协议订单头显示路线明细缺失信息(包括明细不存在和明细无效) public List<object[]> GetScheduleLineItem(string item, string supplier, string plant) { IList<ErrorMessage> errorMessageList = new List<ErrorMessage>(); ZSEKPTH[] headOut = null; ZSEKPTI[] detailOut = null; lock (GetProcOrdersLock) { try { #region 获取指定日期的采购订单物料和计划协议 log.Debug("开始连接Web服务获取采购订单物料和计划协议, " + "物料号: " + item + ",供应商:" + supplier + ", 工厂" + plant); MI_SL_OUTService slOutService = new MI_SL_OUTService(); slOutService.Credentials = base.Credentials; slOutService.Timeout = base.TimeOut; slOutService.Url = ReplaceSAPServiceUrl(slOutService.Url); ZSDELIVERY deliveryIn = new ZSDELIVERY(); deliveryIn.LIFNR = supplier; deliveryIn.WERKS = plant; deliveryIn.MATNR = item; headOut = slOutService.MI_SL_OUT(deliveryIn, out detailOut); log.Debug("从Web服务获取采购订单物料和计划协议完成。"); #endregion } catch (Exception ex) { string logMessage = "连接Web服务获取采购订单物料和计划协议失败。"; log.Error(logMessage, ex); errorMessageList.Add(new ErrorMessage { Template = NVelocityTemplateRepository.TemplateEnum.ImportProcOrderFail, Exception = ex, Message = logMessage }); } } this.SendErrorMessage(errorMessageList); //过滤供应商+物料重复的计划协议 var distinctSaList = from d in headOut group d by new { PartyFrom = d.LIFNR != null ? d.LIFNR : d.RESWK, Item = d.MATNR, EBELN = d.EBELN,//新增了计划协议号 行号 EBELP = d.EBELP } into result select new { PartyFrom = result.Key.PartyFrom, Item = result.Key.Item, EBELN = result.Key.EBELN, EBELP = result.Key.EBELP, List = result.First() }; //查找所有有效的采购路线明细 IList<object[]> flowDetailList = this.genericMgr.FindAllWithNativeSql<object[]>("select m.partyfrom,d.item from scm_flowdet d left join scm_flowmstr m on d.flow = m.code where d.isactive = 1 and m.isactive = 1 and m.type = 1"); //查找物料缺失表 IList<ScheduleLineItem> scheduleLineItemList = this.genericMgr.FindAll<ScheduleLineItem>("select s from ScheduleLineItem as s"); List<object[]> missedFlowDetail = new List<object[]>(); if (distinctSaList != null && distinctSaList.Count() > 0) { foreach (var distinctSa in distinctSaList) { var matchedFlowDetail = from f in flowDetailList where f[0].ToString() == distinctSa.PartyFrom && f[1].ToString() == distinctSa.Item select f; //没找到有效的路线明细 if (matchedFlowDetail == null || matchedFlowDetail.Count() == 0) { missedFlowDetail.Add(new object[] { distinctSa.PartyFrom, distinctSa.Item, distinctSa.EBELN, distinctSa.EBELP }); ////缺失表中不存在,则新增 //if (matchedScheduleLineItem == null || matchedScheduleLineItem.Count() == 0) //{ // ScheduleLineItem scheduleLineItem = new ScheduleLineItem(); // scheduleLineItem.Supplier = distinctSa.PartyFrom; // scheduleLineItem.Item = distinctSa.Item; // scheduleLineItem.IsClose = false; // lesMgr.Create(scheduleLineItem); //} ////如果缺失表已存在,但状态为关闭则重新打开 //else //{ // ScheduleLineItem scheduleLineItem = scheduleLineItemList[0]; // if (scheduleLineItem.IsClose) // { // scheduleLineItem.IsClose = false; // lesMgr.Update(scheduleLineItem); // } //} } //找到路线明细 //else //{ // //如果缺失表有记录,且状态不是关闭,则关闭 // if (scheduleLineItemList != null && scheduleLineItemList.Count > 0) // { // if (!scheduleLineItemList[0].IsClose) // { // scheduleLineItemList[0].IsClose = true; // lesMgr.Update(scheduleLineItemList[0]); // } // } //} } } return missedFlowDetail; }