• PTC FlexPLM rfa 常用功能api


    1.根据款号查询产品
    public LCSProduct GetProductByName(String SKC) throws WTException {
            //声明查询
            PreparedQueryStatement statement = new PreparedQueryStatement();
            statement.appendFromTable("LCSPRODUCT");
            //获取FlexType类型,也就是系列
            String flextypePath = "Product"; 
            FlexType flextype = FlexTypeCache.getFlexTypeFromPath(flextypePath);// the flextype of product flextype
            //设置SQL语句的列名
            String columnFtaName = null;        
            columnFtaName = flextype.getAttribute("productName").getVariableName();
            statement.appendSelectColumn("LCSPRODUCT", columnFtaName);        
            statement.appendSelectColumn("LCSPRODUCT", "BRANCHIDITERATIONINFO");        
            //设置SQL中的Where条件
            //款号条件
            if(SKC.trim().length()>0){
                statement.appendAndIfNeeded();
                statement.appendCriteria(new Criteria("LCSPRODUCT",flextype.getAttribute("EPAstyleNumber").getVariableName(),SKC,Criteria.EQUALS));
            }        
            statement.appendAndIfNeeded(); //版本号为A
            statement.appendCriteria(new Criteria("LCSPRODUCT", "VERSIONIDA2VERSIONINFO", "A", Criteria.EQUALS));        
            statement.appendAndIfNeeded();//并且为最大版本号
            statement.appendCriteria(new Criteria("LCSPRODUCT", "LATESTITERATIONINFO", "1", Criteria.EQUALS));        
            SearchResults results = LCSQuery.runDirectQuery(statement);//执行查询
            Vector vRlt = results.getResults(); //获取所有行的信息
            int iRecNum = vRlt.size();        
            if (iRecNum == 0 || iRecNum > 1) {
                System.out.println("1-无法定位产品");
                return null;
            }
            FlexObject obj = (FlexObject) vRlt.get(0);//获取产品
            String oid="VR:com.lcs.wc.product.LCSProduct:"+obj.getString("LCSPRODUCT.BRANCHIDITERATIONINFO");//取出该产品的oid
            //通过接口查询处产品实体
            return (LCSProduct)(new LCSProductQuery()).findObjectById(oid);
        }
    2.根据产品获取所属季节对象
    public LCSSeason GetSeasonByProduct(LCSProduct product)throws Exception{
            SeasonProductLocator seasonProductLocator = new SeasonProductLocator();
            LCSSeasonProductLink seasonProductLink = seasonProductLocator.getSeasonProductLink(product);
            LCSSeason season = (LCSSeason)seasonProductLocator.getSeasonRev(seasonProductLink);
            return season;
        }
    3.获取季节和产品的关联对象
    SeasonProductLocator seasonProductLocator = new SeasonProductLocator();
    LCSSeasonProductLink seasonProductLink = seasonProductLocator.getSeasonProductLink(product);
    4.获取产品的采购来源(1:m)
       Collection sourcing = LCSSourcingConfigQuery.getSourcingConfigsForProduct(product);
        Iterator it = sourcing.iterator();
        LCSSourcingConfig configSource=null;
        while (it.hasNext()) {
            configSource = (LCSSourcingConfig)it.next();
        }
    5.获取产品采购来源下的所有规格
    SearchResults gg = FlexSpecQuery.findSpecsByOwner((WTPartMaster)product.getMaster(), (WTPartMaster)season.getMaster(), null, null);
    Collection coll = LCSQuery.getObjectsFromResults(gg, "VR:com.lcs.wc.specification.FlexSpecification:", "FLEXSPECIFICATION.BRANCHIDITERATIONINFO");
        for(int n=0;n<coll.size();n++){
            specification = (FlexSpecification) coll.toArray()[n];
        }
    6.获取产品下的所有图像文档集合
        LCSProductQuery prodQuery = new LCSProductQuery();
        Collection prodImagePages = prodQuery.findImagePages(product, null, null, true);
        prodImagePages = CollectionUtil.distinctResults(prodImagePages, "LCSDOCUMENT.BRANCHIDITERATIONINFO");
        Iterator imagePageIter = prodImagePages.iterator();
        while(imagePageIter.hasNext()){
           FlexObject obj = (FlexObject) imagePageIter.next();
           ...
        } 
    7.获取产品下的所有工艺包
    Collection construction = LCSQuery.runDirectQuery(LCSConstructionQuery.findConstructionForProductQuery(product, null, true)).getResults();
        Iterator constIter = construction.iterator();
        while(constIter.hasNext()){
            FlexObject obj = (FlexObject) constIter.next();
        }   
    8.获取产品下的所有版型集合
    Collection measurements = LCSQuery.runDirectQuery(LCSMeasurementsQuery.findMeasurmentsForProductQuery(product, null, true)).getResults();
        Iterator measIter = measurements.iterator();
        while(measIter.hasNext()){
            FlexObject obj = (FlexObject) measIter.next();
        } 
    9.获取产品下的所有BOM
    LCSFlexBOMQuery bomQuery = new LCSFlexBOMQuery();
        QueryStatement bomQueryStatement = bomQuery.findBOMPartsForOwnerQuery((WTPartMaster)product.getMaster(), "", true);
        Collection bomResults = LCSQuery.runDirectQuery(bomQueryStatement).getResults();
        Iterator bomIter = bomResults.iterator();
        while(bomIter.hasNext()){
             FlexObject obj = (FlexObject) bomIter.next();
        }    
    10.给FlexModel批量赋值,Collection操作
            Map specMap=new HashMap();
        specMap.put("specOwnerId",specOwnerId);
        specMap.put("sourceIds",sourceIds);
        specMap.put("specSourceId",specSourceId);
        specMap.put("specSeason",specSeason);
        specMap.put("typeId",typeId);
        specMap.put(att1Name,"颁行");
        //操作Collection
        Collection c_sourceIds = new HashSet();
        c_sourceIds.add(sourceIds);
            AttributeValueSetter.setAllAttributes(flexSpecModel, specMap);    
    11.获取产品的颜色
    public String GetProductColor(LCSProduct product){
            try{
                 String str="";
                 LCSSKUQuery query = new LCSSKUQuery();
                 Collection skuList = query.findSKUs(product);
                 for (Iterator iter = skuList.iterator(); iter.hasNext();) {
                    LCSSKU sku=(LCSSKU)iter.next();
                    str+=sku.getName().replace(" ("+product.getValue("productName")+")","\");
                }
                if(str=="") return "无";
                return str.substring(0,str.length()-1);
            }
            catch(Exception e){
                return "ERROR";
            }
        }
    12.根据用户名,获取用户对象
    public WTUser getUser(String name) throws WTException {   
            Enumeration enumUser = OrganizationServicesHelper.manager.findUser(WTUser.NAME, name);   
            WTUser user = null;   
            if (enumUser.hasMoreElements())   
                user = (WTUser) enumUser.nextElement();   
      
            if (user == null) {   
                enumUser = OrganizationServicesHelper.manager.findUser(WTUser.FULL_NAME, name);   
                if (enumUser.hasMoreElements())   
                    user = (WTUser) enumUser.nextElement();   
            }
            if (user == null) {   
                throw new WTException("系统中不存在用户名为'" + name + "'的用户!");   
            }   
            return user;   
        }
    13.FlexPLM键值对查找
    public String GetBusinessObjDispKey(String Key,String Disp,String path,String Att){
            try{
                //准备关键字和值的转换
                FlexTypeAttribute LoadAtt=FlexTypeCache.getFlexTypeFromPath(path).getAttribute(Att);
                Collection pathData = LoadAtt.getAttValueList().getDataSet();            
                for(Iterator iter=pathData.iterator();iter.hasNext();){
                    FlexObject fo=(FlexObject)iter.next();
                    String key=fo.getString("KEY");
                    String disp=fo.getString("VALUE_ZH_CN");
                    if(!Key.equals("") && key.equals(Key))
                        return disp;
                    else if(!Disp.equals("") && disp.equals(Disp))
                        return key;
                }
                return Key;
            }
            catch(Exception e){
                System.out.println("GetValueByKey====Error:"+e);
                return "";        
            }
        }
    14.获取打样品颜色列表
    FlexTypeAttribute LoadAtt=FlexTypeCache.getFlexTypeFromPath("Business Object\PTCOListOfValue\PTCOCommonLov\PTCOCommon1Lov").getAttribute("LovSampleColor");
            Collection pathData = LoadAtt.getAttValueList().getDataSet();
            for(Iterator iter=pathData.iterator();iter.hasNext();){
                FlexObject fo=(FlexObject)iter.next();
                String key=fo.getString("KEY");
                String disp=fo.getString("VALUE_ZH_CN");
            }
    15.根据产品和用户获取用户下的所有工作流,并驱动执行
    String OjbectID="VR:com.lcs.wc.product.LCSProduct:"+(int)spl.getProductSeasonRevId();
            //获取用户实体
            WTUser user = getUserFromName(UserName);
            //根据用户和ObjectID定位项目
            SearchResults res = (new LCSWorkitemQuery()).getUserWorkList(user,OjbectID);
            Collection coll = res.getResults();
            System.out.println("根据用户和ObjectID获取" + coll.size());
            if(coll.size()<=0) {
                out.println("1-没有找到该工作项!");
                return;
            }
            String WorkName="",WorkItemID="";
            for (int i = 0; i < coll.size(); i++) {
                FlexObject item=(FlexObject)coll.toArray()[i];            
                System.out.println(item);
                WorkName=item.getString("WFASSIGNEDACTIVITY.NAME");
                WorkItemID="OR:wt.workflow.work.WorkItem:"+item.getString("WORKITEM.IDA2A2");
            }
            if(!WorkName.equals("商品部主导初样评审"))
            {
                out.println("1-状态错误");
                return;
            }
            //执行工作流
            String workIds = "|~*~|"+WorkItemID;
            Collection workIdsCollection = MOAHelper.getMOACollection(workIds);
            WFHelper.getService().processWFTasks(workIdsCollection, workEvent);
    16.获取产品下的尺码
    Collection productSizeCats = new SizingQuery().findProductSizeCategoriesForProduct(product).getResults();
        Iterator itor=productSizeCats.iterator();
        String productSizeCategory="";
        while(itor.hasNext()){
            FlexObject obj = (FlexObject)itor.next();
            if(obj.getString("SIZECATEGORY.NAME").equals(brand)){
                productSizeCategory="OR:com.lcs.wc.measurements.ProductSizeCategory:"+obj.getString("PRODUCTSIZECATEGORY.IDA2A2");
                break;
            }
        }
    17.jsp页面接收xml流,格式化为字符串,打印
    InputStream input = request.getInputStream();
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            byte buffer[] = new byte[1024];
            int len = -1;
            try {
                while ((len = input.read(buffer, 0, buffer.length)) > 0) {
                    output.write(buffer, 0, len);
                }
            } finally {
                if (output != null)
                    output.close();
            }
            buffer = output.toByteArray();
            if (buffer == null || buffer.length == 0) {
                throw new LCSException(RB.XML, "noDataForProduct_ERR", RB.objA);
            }
    
            if (DEBUG) {
                String message = new String(buffer, DEFAULT_ENCODING);
                System.out.println("-----------------");
                System.out.println("XML message="+message);
            }
  • 相关阅读:
    bean的singleton(没有看到生命周期范围??)
    ApplicationContext中getBean详解
    mybatis基础之二
    mybatis基础之一
    JDOM读取xml
    SSH整合最简单的一个例子
    基础学习问题
    2015年2.9--2.15号第一周计划
    freertos的钩子函数
    IAR环境搭建注意点
  • 原文地址:https://www.cnblogs.com/qidian10/p/3143288.html
Copyright © 2020-2023  润新知