public override object Do(object obj) { CreateItemMasterSV bpObj = (CreateItemMasterSV)obj; StringBuilder strbResult = new StringBuilder(); #region 基础校验&前提检查 if (string.IsNullOrEmpty(bpObj.ItemInfo)) { logger.Error(string.Format("创建料品失败:传入参数ItemInfo为空。")); strbResult.AppendFormat(string.Format("<ResultInfo Error={0} />", "创建料品失败:传入参数ItemInfo为空。")); return(strbResult.ToString()); } ItemInfo iteminfoAll = new ItemInfo(); ContextInfo cxtInfo = new ContextInfo(); try { iteminfoAll = XmlSerializerHelper.XmlDeserialize <ItemInfo>(bpObj.ItemInfo, Encoding.Unicode); cxtInfo = XmlSerializerHelper.XmlDeserialize <ContextInfo>(bpObj.ContextInfo, Encoding.Unicode); } catch (Exception ex) { logger.Error(string.Format("反序列化ItemInfo失败:{0}", bpObj.ItemInfo)); strbResult.AppendFormat(string.Format("<ResultInfo Error={0} />", string.Format("反序列化ItemInfo失败:{0}", bpObj.ItemInfo))); return(strbResult.ToString()); } if (iteminfoAll.ItemMasters.Count <= 0) { logger.Error(string.Format("传入的ItemInfo中没有料品信息")); strbResult.AppendLine(string.Format("<ResultInfo Error={0} />", "传入的ItemInfo中没有料品信息")); return(strbResult.ToString()); } if (string.IsNullOrEmpty(bpObj.ItemModule)) { logger.Error(string.Format("创建料品失败:传入模板料品编号ItemModule为空。")); strbResult.AppendLine(string.Format("<ResultInfo Error={0} />", "创建料品失败:传入模板料品编号ItemModule为空。")); return(strbResult.ToString()); } Organization beOrgContext = Organization.FindByCode(cxtInfo.OrgCode); ItemMaster beItemMaster = ItemMaster.Finder.Find("Code=@code and Org=@org", new OqlParam[] { new OqlParam(bpObj.ItemModule), new OqlParam(beOrgContext.ID) }); if (beItemMaster == null) { logger.Error(string.Format("模板料品ItemModule编号{0},组织【{1}】下无法找到!", bpObj.ItemModule, beOrgContext.Name)); strbError.AppendLine(string.Format("<ResultInfo Error={0} />", string.Format("模板料品ItemModule编号{0},组织【{1}】下无法找到!", bpObj.ItemModule, beOrgContext.Name))); return(strbResult.ToString()); } ISVItem.ItemMasterDTO dtoItemModule = null; try { //查询模板料品 ISVItem.BatchQueryItemByDTOSRV srvQueryItemDTO = new ISVItem.BatchQueryItemByDTOSRV(); List <ISVItem.QueryItemDTO> lstQueryItem = new List <ISVItem.QueryItemDTO>(); ISVItem.QueryItemDTO itemQueryModuleDTO = new ISVItem.QueryItemDTO(); itemQueryModuleDTO.ItemMaster = new CommonArchiveDataDTO(); itemQueryModuleDTO.ItemMaster.ID = beItemMaster.ID; itemQueryModuleDTO.ItemMaster.Name = beItemMaster.Name; itemQueryModuleDTO.ItemMaster.Code = beItemMaster.Code; itemQueryModuleDTO.Org = new CommonArchiveDataDTO(); itemQueryModuleDTO.Org.ID = beOrgContext.ID; itemQueryModuleDTO.Org.Name = beOrgContext.Name; itemQueryModuleDTO.Org.Code = beOrgContext.Code; lstQueryItem.Add(itemQueryModuleDTO); srvQueryItemDTO.QueryItemDTOs = lstQueryItem; List <ISVItem.ItemMasterDTO> lstQueryItemModule = srvQueryItemDTO.Do(); if (lstQueryItemModule != null && lstQueryItemModule.Count > 0) { dtoItemModule = lstQueryItemModule[0]; } else { throw new Exception(string.Format("没有找到模板料品{0}", beItemMaster.Code)); } } catch (Exception ex) { logger.Error(string.Format("获取模板料品DTO处理异常:{0}.", ex.Message)); strbError.AppendLine(string.Format("<ResultInfo Error={0} />", string.Format("获取模板料品DTO处理异常:{0}.", ex.Message))); return(strbResult.ToString()); } #endregion ISVItem.BatchModifyItemByDTOSRV svModify = new ISVItem.BatchModifyItemByDTOSRV(); List <ISVItem.ItemMasterDTO> lstItemModifyDTO = new List <ISVItem.ItemMasterDTO>(); ISVItem.BatchCreateItemByDTOSRV svCreate = new ISVItem.BatchCreateItemByDTOSRV(); List <ISVItem.ItemMasterDTO> lstItemCreateDTO = new List <ISVItem.ItemMasterDTO>(); User beUser = User.Finder.FindByID(cxtInfo.UserID); ContextDTO dtoContext = new ContextDTO(); dtoContext.CultureName = cxtInfo.CultureName; // "zh-CN"; dtoContext.UserCode = beUser.Code; //默认:系统管理员admin dtoContext.EntCode = cxtInfo.EnterpriseCode; // "";//测试默认公司:.正式使用请根据需要指定。 dtoContext.OrgCode = cxtInfo.OrgCode; // svModify.ContextDTO = dtoContext; svCreate.ContextDTO = dtoContext; Int64 l = 1; string strErrorItem = "<errorItem code=\"{0}\" errorDescription=\"{1}\" />"; string strInfoItem = "<infoItem code=\"{0}\" />"; try { StringBuilder strbPLMLog = new StringBuilder(); strbPLMLog.AppendLine("<PLMLog>"); foreach (var item in iteminfoAll.ItemMasters) { //strbPLMLog.AppendLine(String.Format("<ItemMaster code=\"{0}\" itemProperty14=\"{1}\" />", item.ItemCode, // String.IsNullOrEmpty(item.ItemProperty14) ? "0" : item.ItemProperty14));//记录传入的物料和图号ItemProperty14 ItemMaster beItemExists = null; if (!string.IsNullOrEmpty(item.ItemCode)) { strbPLMLog.AppendLine(String.Format("<ItemMaster code=\"{0}\" />", item.ItemCode));//记录传入的料号 beItemExists = ItemMaster.Finder.Find("Org=@org and Code=@code ", new OqlParam[] { new OqlParam(beOrgContext.ID), new OqlParam(item.ItemCode) }); } if (beItemExists == null) { #region 生成ItemMaster编码 //strbPLMLog.AppendLine(String.Format("<ItemMaster code=\"{0}\" />", item.ItemCode));//记录传入的料号 string strNewItemCode = getNewCode(item.MainCategoryCode, beItemMaster); item.ItemCode = strNewItemCode; #endregion //只在新增时对单位进行检查。修改时可以不提供单位,沿用原单位。 UOM beUOM = UOM.FindByCode(item.UOMCode); if (beUOM == null) { strbError.AppendLine(string.Format(strErrorItem, item.ItemCode, string.Format("单位{0}在U9中不存在。", item.UOMCode))); continue; } #region 校验传入的料品是否存在.如果不存在,则转入到料品创建服务CreateItemSv中。 ISVItem.ItemMasterDTO dtoItemCreate = CreateItemMasterDTO(dtoItemModule, item, cxtInfo); lstItemCreateDTO.Add(dtoItemCreate); #endregion } else { strbPLMLog.AppendLine(String.Format("<ItemMaster code=\"{0}\" />", item.ItemCode));//记录传入的料号 #region 若存在则转入到修改服务ModifyItemMasterDTO中,无料品版本管理。 ISVItem.ItemMasterDTO dtoItemCreate = ModifyItemMasterDTO(beItemExists, item, cxtInfo, false); lstItemModifyDTO.Add(dtoItemCreate); #endregion } l++; } strbPLMLog.AppendLine("</PLMLog>"); logger.Error(strbPLMLog);//传入物料号和图号日志记录。 if (lstItemCreateDTO.Count > 0) { svCreate.ItemMasterDTOs = lstItemCreateDTO; ItemMaster.EntityList lstCreateItem = svCreate.Do(); foreach (var item in lstCreateItem) { strbSuccess.AppendLine(string.Format(strInfoItem, item.Code)); } } if (lstItemModifyDTO.Count > 0) { svModify.ItemMasterDTOs = lstItemModifyDTO; ItemMaster.EntityList lstModifyItem = svModify.Do(); foreach (var item in lstModifyItem) { strbSuccess.AppendLine(string.Format(strInfoItem, item.Code)); } } strbResult.AppendLine("<ResultInfo>"); strbResult.AppendLine(strbError.ToString()); strbResult.AppendLine(strbSuccess.ToString()); strbResult.AppendLine("</ResultInfo>"); logger.Info(strbResult.ToString());//日志记录 return(strbResult.ToString()); } catch (Exception ex) { logger.Error(string.Format("PLM调用料品接口服务失败:{0}。", ex.Message)); strbResult.AppendFormat(string.Format("<ResultInfo Error={0} />", string.Format("PLM调用料品接口服务失败:{0}。", ex.Message))); return(strbResult.ToString()); } }
/// <summary> /// 创建修改料品服务的DTO /// </summary> /// <param name="_itemModule"></param> /// <returns></returns> private ISVItem.ItemMasterDTO ModifyItemMasterDTO(ItemMaster _itemExists, ItemMasterCustData _itemData, ContextInfo _cxtInfo, bool _isNewVersion) { ISVItem.BatchQueryItemByDTOSRV srvQueryItemDTO = new ISVItem.BatchQueryItemByDTOSRV(); List <ISVItem.QueryItemDTO> lstQueryDTO = new List <ISVItem.QueryItemDTO>(); ISVItem.QueryItemDTO dtoExists = new ISVItem.QueryItemDTO(); dtoExists.ItemMaster = new CommonArchiveDataDTO(); dtoExists.ItemMaster.ID = _itemExists.ID; lstQueryDTO.Add(dtoExists); srvQueryItemDTO.QueryItemDTOs = lstQueryDTO; List <ISVItem.ItemMasterDTO> lstItemMasterDTO = srvQueryItemDTO.Do(); ISVItem.ItemMasterDTO dtoItemModify = null; if (lstItemMasterDTO != null && lstItemMasterDTO.Count > 0) { dtoItemModify = lstItemMasterDTO[0]; dtoItemModify.SPECS = _itemData.Specs;//规格 if (!string.IsNullOrEmpty(_itemData.ItemForm)) { dtoItemModify.ItemForm = ItemTypeEnum.GetFromValue(_itemData.ItemForm); //料品形态 } dtoItemModify.ItemFormAttribute = ItemTypeAttributeEnum.GetFromName(_itemData.ItemFormAttribute); //料品形态属性 User beUser = User.Finder.FindByID(_cxtInfo.UserID); dtoItemModify.ModifiedBy = beUser.Name;//修改人 dtoItemModify.ModifiedOn = DateTime.Now.Date; dtoItemModify.Effective.IsEffective = _itemData.Effective; //若单位为提供,则沿用原单位 CommonArchiveDataDTO dtoUOM = new CommonArchiveDataDTO(); if (String.IsNullOrEmpty(_itemData.UOMCode)) { dtoUOM.Code = _itemExists.InventoryUOM.Code; dtoUOM.ID = _itemExists.InventoryUOM.ID; dtoUOM.Name = _itemExists.InventoryUOM.Name; } else { UOM beUOM = UOM.FindByCode(_itemData.UOMCode); dtoUOM.Code = beUOM.Code; dtoUOM.ID = beUOM.ID; dtoUOM.Name = beUOM.Name; } dtoItemModify.InventoryUOM = dtoUOM; //库存主单位 dtoItemModify.InventorySecondUOM = dtoUOM; //库存单位 dtoItemModify.BulkUom = dtoUOM; //体积单位 dtoItemModify.CostUOM = dtoUOM; //成本单位 dtoItemModify.ManufactureUOM = dtoUOM; //生产单位 dtoItemModify.MaterialOutUOM = dtoUOM; //领料单位 dtoItemModify.PurchaseUOM = dtoUOM; //采购单位 dtoItemModify.PriceUOM = dtoUOM; //计价单位 dtoItemModify.SalesUOM = dtoUOM; //销售单位 dtoItemModify.WeightUom = dtoUOM; //重量单位 StringBuilder strbCombName = new StringBuilder(); strbCombName.AppendFormat("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}", string.IsNullOrEmpty(_itemData.ItemName) ? "0" : _itemData.ItemName, string.IsNullOrEmpty(_itemData.Specs) ? "0" : _itemData.Specs, string.IsNullOrEmpty(_itemData.ItemProperty1) ? "0" : _itemData.ItemProperty1, string.IsNullOrEmpty(_itemData.ItemProperty2) ? "0" : _itemData.ItemProperty2, string.IsNullOrEmpty(_itemData.ItemProperty3) ? "0" : _itemData.ItemProperty3, string.IsNullOrEmpty(_itemData.ItemProperty4) ? "0" : _itemData.ItemProperty4, string.IsNullOrEmpty(_itemData.ItemProperty5) ? "0" : _itemData.ItemProperty5, string.IsNullOrEmpty(_itemData.ItemProperty6) ? "0" : _itemData.ItemProperty6, string.IsNullOrEmpty(_itemData.ItemProperty7) ? "0" : _itemData.ItemProperty7, string.IsNullOrEmpty(_itemData.ItemProperty8) ? "0" : _itemData.ItemProperty8, string.IsNullOrEmpty(_itemData.ItemProperty9) ? "0" : _itemData.ItemProperty9, string.IsNullOrEmpty(_itemData.ItemProperty10) ? "0" : _itemData.ItemProperty10, string.IsNullOrEmpty(_itemData.ItemProperty11) ? "0" : _itemData.ItemProperty11, string.IsNullOrEmpty(_itemData.ItemProperty12) ? "0" : _itemData.ItemProperty12, string.IsNullOrEmpty(_itemData.ItemProperty13) ? "0" : _itemData.ItemProperty13, string.IsNullOrEmpty(_itemData.ItemProperty14) ? "0" : _itemData.ItemProperty14); dtoItemModify.Name = strbCombName.ToString(); //dtoItemModify.Name = _itemData.ItemName;//测试 #region DescFlexField;扩展字段 DescFlexSegments segments = dtoItemModify.DescFlexField; segments.SetValue("PrivateDescSeg5", _itemData.ItemDescSeg5); segments.SetValue("PrivateDescSeg6", _itemData.ItemDescSeg6); segments.SetValue("PrivateDescSeg7", _itemData.ItemDescSeg7); segments.SetValue("PrivateDescSeg8", _itemData.ItemDescSeg8); segments.SetValue("PrivateDescSeg9", _itemData.ItemDescSeg9); segments.SetValue("PrivateDescSeg10", _itemData.ItemDescSeg10); #endregion //无料品版本处理 } return(dtoItemModify); }