package com.vci.client.refquery; import java.util.ArrayList; import java.util.List; import com.vci.client.ui.exception.VCIException; import com.vci.client.common.ClientLog4j; import com.vci.client.common.providers.ServiceProvider; import com.vci.corba.common.VCIError; import com.vci.corba.query.ObjectQueryServicePrx; import com.vci.corba.query.data.RefPath; import com.vci.corba.query.data.RefValue; public class PLMReferenceQueryFacade { private static ObjectQueryServicePrx refService = null; private RefPath[] clientRefpaths = null; public ObjectQueryServicePrx getRefServer() throws VCIException { if (refService != null) { return refService; } try { return refService = ServiceProvider.getOQService(); } catch (Exception e) { ClientLog4j.logger.error(e.getMessage(), e); throw new VCIException("1", new String[] { e.getMessage() }); } } /** * @param String * [] 参照属性路径信息( referenceDatas): e.g , ( String[] referenceDatas * = new String[] { * "btd.gg=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.ddd.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.gg.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.gg.gg.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.gg.gg.ddd.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , * "btd.gg.gg.gg.ddd.gg.name=22385E82-485C-549D-E2F4-91278E9E0A78,22385E82-485C-549D-E2F4-91278E9E0A75" * , "btd.ddd=22385E82-485C-549D-E2F4-91278E9E0A78", * "btd.ddd.ddd.gg.name=22385E82-485C-549D-E2F4-91278E9E0A78" };) * @param String * 参照属性与标识的分隔符 (split) : e.g,( "=") * @param String * 标识的分隔符 (idSplit) : e.g, (",") * @return RefPath[] 参照信息值对象 * * */ public RefPath[] toRefPath(String[] referenceDatas, String split, String idSplit) { RefPath[] referencePaths = new RefPath[referenceDatas.length]; RefPath[] referencePathsForCorba = new RefPath[referenceDatas.length]; for (int i = referenceDatas.length - 1; i >= 0; i--) { String rPath = referenceDatas[i]; String[] rBelongsIds = rPath.split(split); RefPath referencePath = new RefPath(); RefPath referencePathForCorba = new RefPath(); // path referencePath.path = rBelongsIds[0]; referencePathForCorba.path = rBelongsIds[0]; if (rBelongsIds != null && rBelongsIds.length > 1) { String id = rBelongsIds[1]; String[] ids = id.split(idSplit); RefValue[] values = new RefValue[ids.length]; List valuesForCorba = new ArrayList(); for (int m = 0; m < ids.length; m++) { RefValue value = new RefValue(); value.row = m; value.value = ids[m]; values[m] = value; if (isContained(valuesForCorba, ids[m])) { continue; } valuesForCorba.add(value); } referencePathForCorba.values = valuesForCorba .toArray(new RefValue[valuesForCorba.size()]); referencePath.values = values; } referencePaths[i] = referencePath; referencePathsForCorba[i] = referencePathForCorba; } clientRefpaths = referencePaths; return referencePathsForCorba; } private boolean isContained(List values, String id) { for (RefValue v : values) { if (null != v && v.value.equals(id)) { return true; } } return false; } private int knowPathIndex(String path, RefPath[] returnPaths) { int dbIndex = 0; for (int i = 0; i < returnPaths.length; i++) { if (returnPaths[i].path.equals(path)) { dbIndex = i; break; } } return dbIndex; } private int knowValueIndex(String oid, RefValue[] dbvalues) { int dbIndex = 0; for (int i = 0; i < dbvalues.length; i++) { if (dbvalues[i].value.equals(oid)) { dbIndex = i; break; } } return dbIndex; } private void copy(RefPath[] returnPaths) { for (int m = 0; m < clientRefpaths.length; m++) { RefValue[] values = clientRefpaths[m].values; String path = clientRefpaths[m].path; String[] rootpaths = path.split("\\."); String root = rootpaths[0] + "." + rootpaths[1]; int dbIndex = knowPathIndex(path, returnPaths); int dbrootIndex = knowPathIndex(root, returnPaths); RefValue[] dbvalues = returnPaths[dbIndex].values; RefValue[] rootdbvalues = returnPaths[dbrootIndex].values; for (int n = 0; n < values.length; n++) { String oid = values[n].value; int valueindex = knowValueIndex(oid, rootdbvalues); values[n].value = dbvalues[valueindex].value; } } } public RefPath[] query(String[] references, String toType) throws VCIException, VCIError { ObjectQueryServicePrx server = getRefServer(); RefPath[] referencePaths = this.toRefPath(references, "=", ","); RefPath[] returnPaths = server.getRefResults(referencePaths, toType); copy(returnPaths); return this.clientRefpaths; } public RefPath[] query(String[] references, String[] toTypes) throws VCIException, VCIError { ObjectQueryServicePrx server = getRefServer(); RefPath[] referencePaths = this.toRefPath(references, "=", ","); RefPath[] returnPaths = server.getRefTypesResults(referencePaths, toTypes); copy(returnPaths); return this.clientRefpaths; } public RefPath[] query(String[] references) throws VCIException, VCIError { ObjectQueryServicePrx server = getRefServer(); RefPath[] referencePaths = this.toRefPath(references, "=", ","); long From = System.currentTimeMillis(); RefPath[] returnPaths = server.getRefQueryResults(referencePaths); long to = System.currentTimeMillis(); copy(returnPaths); System.out.println("time cost: " + (to - From) + " ms"); ClientLog4j.logger.debug("time cost: " + (to - From) + " ms"); return this.clientRefpaths; } public static void main(String[] s) { // String two = // "e33666f6-db15-44e9-b0a2-7ca2b001c5f6,7D6FEE4E-91DF-CDF8-A735-6DE3E39157A1"; // // for (int i = 0; i < 10000; i++) { // // //two += "," + UUID.randomUUID(); // // } // String[] referenceDatas = new String[] { "bta.gg=" + // two,"bta.gg.t_oid="+two, // "bta.gg.t_oid.gg.t_oid=" + two, "bta.gg.t_oid.name=" + two, // "bta.gg.t_oid.ddd.name=" + two, "bta.gg.t_oid.ddd=" + two, // "bta.gg.t_oid.ddd.ddd.name=" + two }; String refrenceOids = "A5374FB0-9A14-C053-580E-0E8C36A42DA7,DBA8483C-4DA7-90ED-2DA7-00DC27E19B09,8D86B310-B128-1DDE-03E7-937251F55E7A,BB481B13-F2DE-A1E9-ADB7-4014522CA9FC,FEEEED35-FD6E-E0CC-2059-A4B5A422CFE8,3B471AF4-07C7-85BA-5C36-494DCE759F7B"; String[] referenceDatas = new String[] { // "processcitem.sprocedure=E47ED10F-2897-DB55-C549-114E360ACFCA", // "processcitem.sprocedure.processno=E47ED10F-2897-DB55-C549-114E360ACFCA", // "processcitem.sprocedure.content=E47ED10F-2897-DB55-C549-114E360ACFCA", // "processcitem.sprocedure.equipment=E47ED10F-2897-DB55-C549-114E360ACFCA" // "processcitem.sprocedure.workcenter=E47ED10F-2897-DB55-C549-114E360ACFCA" // "processcitem.ownedchangeorder=794DC0F7-248A-436D-DB6D-0998C3DCF511", // "processcitem.ownedchangeorder.name=794DC0F7-248A-436D-DB6D-0998C3DCF511", // "processcitem.usedbypart=37EDEC00-F3A6-A4D5-23E7-D06846FAB51D", // "processcitem.usedbypart.code=37EDEC00-F3A6-A4D5-23E7-D06846FAB51D", // "processcitem.usedbypart.id=37EDEC00-F3A6-A4D5-23E7-D06846FAB51D", // "processcitem.usedbypart.name=37EDEC00-F3A6-A4D5-23E7-D06846FAB51D" // "processcitem.eprocedure=754AFD8C-0203-B351-0C19-B6E29EB63044", // "processcitem.eprocedure.processno=754AFD8C-0203-B351-0C19-B6E29EB63044", // "processcitem.eprocedure.content=754AFD8C-0203-B351-0C19-B6E29EB63044", // "processcitem.eprocedure.equipment=754AFD8C-0203-B351-0C19-B6E29EB63044", // "processcitem.eprocedure.workcenter=754AFD8C-0203-B351-0C19-B6E29EB63044", // "processcitem.ownedprocess=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.code=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.name=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.ownedppr=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.ownedppr.routecontent=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.pprnode=3B747DC0-7FD0-868A-951E-6C89197B289E", // "processcitem.ownedprocess.pprnodeposition=3B747DC0-7FD0-868A-951E-6C89197B289E" // "input.t_oid=00EC4767-6DAE-C3A3-CD9A-33C832B59636,F2033E00-8D2B-9BDF-2180-17937A2F4FDA,DBEF3A01-381A-8BA8-E4BA-1DE6598294E9", // "input.t_oid.usedbyppart.code=00EC4767-6DAE-C3A3-CD9A-33C832B59636,F2033E00-8D2B-9BDF-2180-17937A2F4FDA,DBEF3A01-381A-8BA8-E4BA-1DE6598294E9", // "input.t_oid.id=00EC4767-6DAE-C3A3-CD9A-33C832B59636,F2033E00-8D2B-9BDF-2180-17937A2F4FDA,DBEF3A01-381A-8BA8-E4BA-1DE6598294E9" // "groupprocessroute.usedbyppart=BB35180E-6C4D-BA95-1A2B-A9D4013A9BA0,D460C91D-527F-0BAF-5E35-F3944DA2B58A", // "groupprocessroute.usedbyppart.code=D460C91D-527F-0BAF-5E35-F3944DA2B58A,D460C91D-527F-0BAF-5E35-F3944DA2B58A" "input.t_oid=57CBC8E1-16CC-C603-0BC1-425A782E7223", "input.t_oid.usedbyppart=57CBC8E1-16CC-C603-0BC1-425A782E7223", "input.t_oid.abcdef=57CBC8E1-16CC-C603-0BC1-425A782E7223", "input.t_oid.usedbyppart.id=57CBC8E1-16CC-C603-0BC1-425A782E7223", "input.t_oid.usedbyppart.name=57CBC8E1-16CC-C603-0BC1-425A782E7223" }; String[] types = new String[]{ "groupprocessroute", "groupprocessroute", "product" }; String type = "plantprocessroute"; PLMReferenceQueryFacade facade = new PLMReferenceQueryFacade(); try { @SuppressWarnings("unused") RefPath[] results = facade.query(referenceDatas, type); // RefPath[] results = facade.query(referenceDatas); System.out.println(); } catch (VCIException e) { e.printStackTrace(); } catch (VCIError e) { e.printStackTrace(); } } }