Exemplo n.º 1
0
        //[OperationBehavior]
        public System.String DoEx(ICommonDataContract commonData, System.String contextInfo, System.String itemModule, System.String itemInfo)
        {
            this.CommonData = commonData;
            try
            {
                BeforeInvoke("UFIDA.U9.Cust.ZX.BaiLiSV.CreateItemMasterSV");
                CreateItemMasterSV objectRef = new CreateItemMasterSV();

                objectRef.ContextInfo = contextInfo;
                objectRef.ItemModule  = itemModule;
                objectRef.ItemInfo    = itemInfo;

                //处理返回类型.
                System.String result = objectRef.Do();
                return(result);

                return(result);
            }
            catch (System.Exception e)
            {
                DealException(e);
                throw;
            }
            finally
            {
                FinallyInvoke("UFIDA.U9.Cust.ZX.BaiLiSV.CreateItemMasterSV");
            }
        }
        public override object Do(object obj)
        {
            CreateItemMasterSV bpObj = (CreateItemMasterSV)obj;

            //get business operation context is as follows
            //IContext context = ContextManager.Context

            //auto generating code end,underside is user custom code
            //and if you Implement replace this Exception Code...
            throw new NotImplementedException();
        }
        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());
            }
        }