博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTC FlexPLM rfa 接口自动创建产品规格
阅读量:6902 次
发布时间:2019-06-27

本文共 11404 字,大约阅读时间需要 38 分钟。

<%-- Copyright (c) 2006 PTC FlexPLM All Rights Reserved --%><%-- /--%><%--  JSP HEADERS --%><%-- /--%><%@ page    language="java"            import= "   java.util.*,                        java.io.*,                        wt.util.*,                        java.net.*,                        com.lcs.wc.util.*,                        com.lcs.wc.document.*,                        com.lcs.wc.flextype.*,                        com.lcs.wc.product.*,                        com.lcs.wc.foundation.LCSQuery,                        com.lcs.wc.db.SearchResults,                        com.lcs.wc.client.web.PageManager,                        com.lcs.wc.client.web.WebControllers,                        com.lcs.wc.client.Activities,                        com.lcs.wc.flextype.*,                        com.lcs.wc.foundation.*,                        com.lcs.wc.db.*,                        com.lcs.wc.part.*,                        wt.part.*,                        wt.part.WTPartMaster,                        com.lcs.wc.sourcing.*,                        com.lcs.wc.season.*,                        com.lcs.wc.specification.*                        "%>  <%-- /--%><%--  BEAN INITIALIZATIONS ///--%><%-- /--%>
<%-- --%><%-- // INITIALIZATION JSP CODE /--%><%-- --%><%! public static final String DEFAULT_ENCODING = LCSProperties.get("com.lcs.wc.util.CharsetFilter.Charset","UTF-8"); public static boolean DEBUG = LCSProperties.getBoolean("jsp.xml.AIPlugin.verbose"); public static String FILE_PATH = null; static { try { WTProperties wtproperties = WTProperties.getLocalProperties(); String wtHome = wtproperties.getProperty("wt.home"); FILE_PATH = FormatHelper.formatOSFolderLocation(LCSProperties.get("com.lcs.wc.content.documentfilePath", "C:")); FILE_PATH = wtHome + FILE_PATH; } catch(Exception e){ e.printStackTrace(); } }%><%-- /--%><%-- PROCESSING --%><%-- /--%><% try { String fileName = request.getHeader("content-location"); if (!FormatHelper.hasContent(fileName)) { throw new LCSException(RB.DOCUMENT, "noFileName_ERR", RB.objA); } fileName = FILE_PATH + File.separatorChar + fileName; fileName = FileRenamer.rename(fileName); System.out.println("\t File Name " + fileName); boolean hasError = false; InputStream input = request.getInputStream(); FileOutputStream output = new FileOutputStream(fileName); 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(); } File file = new File(fileName); if (!file.exists()) { System.out.println("\t No File "); //throw new LCSException("No File " + fileName); Object params[] = { fileName }; throw new LCSException(RB.DOCUMENT, "noFile_ERR", params); } if (file.length() == 0) { System.out.println("\t Zero Length file"); Object params[] = { fileName }; throw new LCSException(RB.DOCUMENT, "noContentInFile_MSG", params); } FileUploadHelper.processFile(fileName, file, documentModel, request.getHeader("content-location"), request.getParameter("specificationId")); LCSDocument document = documentModel.getBusinessObject(); document = (LCSDocument)wt.fc.PersistenceHelper.manager.refresh(document); String xmlStr = new XMLHelper().generateXML(document); buffer = xmlStr.getBytes(DEFAULT_ENCODING); response.setContentLength(buffer.length); response.setStatus(response.SC_OK); System.out.println("\t Response " + response.SC_OK); //changed by jackchain //2012-11-19 //自动创建产品规格,关联产品文档 //Start System.out.println("\t Jackchain reached here 到此一游!"); String owner=""+document.getValue("ownerReference");//获取WTPartMaster wt.part.WTPartMaster wt = (wt.part.WTPartMaster)(LCSQuery.findObjectById(owner)); String SKU=wt.getName(); //声明查询 PreparedQueryStatement statement = new PreparedQueryStatement(); statement.appendFromTable("LCSPRODUCT"); String flextypePath = "Product"; FlexType flextype = FlexTypeCache.getFlexTypeFromPath(flextypePath); statement.appendSelectColumn("LCSPRODUCT", flextype.getAttribute("productName").getVariableName()); statement.appendSelectColumn("LCSPRODUCT", "BRANCHIDITERATIONINFO"); //款号条件 if(SKU.trim().length()>0){ statement.appendAndIfNeeded(); statement.appendCriteria(new Criteria("LCSPRODUCT",flextype.getAttribute("EPAstyleNumber").getVariableName(),SKU,Criteria.EQUALS)); } statement.appendAndIfNeeded(); 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 == 1) {
//找到产品 FlexObject obj = (FlexObject) vRlt.get(0);//获取产品 String oid="VR:com.lcs.wc.product.LCSProduct:"+obj.getString("LCSPRODUCT.BRANCHIDITERATIONINFO"); LCSProduct product = (LCSProduct)(new LCSProductQuery()).findObjectById(oid); CreateSpec(product); } else{ System.out.println("EP > not find product :"+SKU+" the specfication created failure!"); } //End response.getWriter().write(xmlStr); } catch (Throwable e) { e.printStackTrace(); String msg = new XMLHelper().generateErrorMessage(e); LCSErrorLog.logRequest(request, msg); System.out.println("\t Response " + response.SC_INTERNAL_SERVER_ERROR); byte[] buffer = msg.getBytes(DEFAULT_ENCODING); response.setContentLength(buffer.length); response.setContentType("text/plain"); response.setStatus(response.SC_INTERNAL_SERVER_ERROR); java.io.Writer writer = response.getWriter(); writer.write(msg); } %><%! public void CreateSpec(LCSProduct product){ //建立关联 try{ String componentIds=""; LCSProductQuery prodQuery = new LCSProductQuery(); Collection prodImagePages = prodQuery.findImagePages(product, null, null, true); prodImagePages = CollectionUtil.distinctResults(prodImagePages, "LCSDOCUMENT.BRANCHIDITERATIONINFO"); FlexType imagePageRootType = FlexTypeCache.getFlexTypeFromPath("Document\\Images Page"); Iterator imagePageIter = prodImagePages.iterator(); while(imagePageIter.hasNext()){ FlexObject obj_temp = (FlexObject) imagePageIter.next(); componentIds = "VR:com.lcs.wc.document.LCSDocument:" + obj_temp.getString("LCSDOCUMENT.BRANCHIDITERATIONINFO"); } if(componentIds.equals("")) { System.out.println("AIPluginUploadContent.jsp > CreateSpec > 没有找到图片"); return; } //获取季节 String sourceIds=""; String specOwnerId=""; Collection sourcing = LCSSourcingConfigQuery.getSourcingConfigsForProduct(product); Iterator it = sourcing.iterator(); LCSSourcingConfig configSource=null; boolean isfindLY=false; while (it.hasNext()) { configSource = (LCSSourcingConfig)it.next(); if(configSource.getSourcingConfigName().contains("001")&&configSource.getSourcingConfigName().contains("Primary")){ sourceIds=("VR:com.lcs.wc.sourcing.LCSSourcingConfig:"+configSource.getBranchIdentifier()); specOwnerId=("OR:"+configSource.getProductMaster()); break; } } if(sourceIds.equals("")||specOwnerId.equals("")){ System.out.println("AIPluginUploadContent.jsp > CreateSpec > 没有找到采购来源"); return; } //获取季节 String seasonIds=""; SeasonProductLocator seasonProductLocator = new SeasonProductLocator(); LCSSeasonProductLink seasonProductLink = seasonProductLocator.getSeasonProductLink(product); LCSSeason season = (LCSSeason)seasonProductLocator.getSeasonRev(seasonProductLink); seasonIds=("VR:com.lcs.wc.season.LCSSeason:"+season.getBranchIdentifier()); SearchResults rs = FlexSpecQuery.findSpecsByOwner((WTPartMaster)product.getMaster(), (WTPartMaster)season.getMaster(), null, null); Collection coll = LCSQuery.getObjectsFromResults(rs, "VR:com.lcs.wc.specification.FlexSpecification:", "FLEXSPECIFICATION.BRANCHIDITERATIONINFO"); if(coll.size()>0){ System.out.println("AIPluginUploadContent.jsp > CreateSpec > 已存在规格!"); return; } System.out.println("sourceIds = " + sourceIds); System.out.println("seasonIds = " + seasonIds); System.out.println("specOwnerId = " + specOwnerId); System.out.println("componentIds = " + componentIds); Collection listSourceIDs = new ArrayList(); listSourceIDs.add(sourceIds); Collection listSeasonIds = new ArrayList(); listSeasonIds.add(seasonIds); Collection listComponentIds = new ArrayList(); listComponentIds.add(componentIds); FlexType specFlexType = FlexTypeCache.getFlexTypeFromPath("Specification"); FlexSpecificationClientModel flexSpecModel = new FlexSpecificationClientModel(); flexSpecModel.setFlexType(specFlexType); flexSpecModel.setSpecOwnerId(specOwnerId); flexSpecModel.setSpecSourceId(sourceIds); flexSpecModel.setTypeId("OR:"+specFlexType.getIdentity()); flexSpecModel.setValue("specName","自动生成"); Map paramsMap=new HashMap(); paramsMap.put("parentSpec",""); (new FlexSpecLogic()).saveSpec(flexSpecModel,listSourceIDs,listSeasonIds,listComponentIds,paramsMap); System.out.println("AIPluginUploadContent.jsp > CreateSpec > successful"); } catch(Exception error){ System.out.println("AIPluginUploadContent.jsp > CreateSpec > "+error); } }%>

转载地址:http://jlldl.baihongyu.com/

你可能感兴趣的文章
演示:IPv6全球单播地址的配置
查看>>
微信公众号还适合投资和创业吗?
查看>>
太狗血了!分享一次网站百度收录排名异常的检查记录
查看>>
Exchange server 2016 无人值守安装
查看>>
Powershell管理系列(三十三)PowerShell操作之查询AD账号对应的OU存放位置
查看>>
网上出售企业支付宝骗局,不看后悔
查看>>
2012体感来袭
查看>>
ELK(elasticsearch5.0)head插件安装配置
查看>>
马化腾IT领袖峰会力推,微信小程序即将迎来爆发拐点
查看>>
su 和 sudo、su root和su - root 区别
查看>>
幻灯片在网页设计中应用的21个优秀案例
查看>>
javascript js 判断页面是否加载完成
查看>>
Ural_1494. Monobilliards(栈)
查看>>
IBM_WebSpwhere_Portal WIN7安不上解决
查看>>
基于ArcGIS10.0和Oracle10g的空间数据管理平台十六(C#开发)-空间数据编辑(上)...
查看>>
Xml匹配为对象集合(两种不同的方式)
查看>>
sql server join
查看>>
翻译:Contoso 大学 - 6 – 更新关联数据
查看>>
无线AP不能连接太多设备
查看>>
LINQ - Restriction Operators
查看>>