//01. 零件号 返回 WTPart对象
public static WTPart getWTPartByNumber(String
paramString)
throws
WTException
{
WTPart
localWTPart = null;
QuerySpec
localQuerySpec = null;
QueryResult
localQueryResult = null;
localQuerySpec = new QuerySpec(WTPartMaster.class);
SearchCondition localSearchCondition = new
SearchCondition(WTPartMaster.class, "number", "LIKE",
paramString);
localQuerySpec.appendSearchCondition(localSearchCondition);
localQueryResult =
PersistenceHelper.manager.find(localQuerySpec);
if
(localQueryResult.hasMoreElements())
{
WTPartMaster localWTPartMaster =
(WTPartMaster)localQueryResult.nextElement();
localWTPart = getLatestPartByPartMaster(localWTPartMaster);
}
return
localWTPart;
}
//02.零件号 返回 WTPartMaster 对象
public static WTPartMaster
getWTPartMasterByNumber(String paramString)
throws
WTException
{
WTPartMaster
localWTPartMaster = null;
QuerySpec
localQuerySpec = null;
QueryResult
localQueryResult = null;
localQuerySpec = new QuerySpec(WTPartMaster.class);
SearchCondition localSearchCondition = new
SearchCondition(WTPartMaster.class, "number", "LIKE",
paramString);
localQuerySpec.appendSearchCondition(localSearchCondition);
localQueryResult =
PersistenceHelper.manager.find(localQuerySpec);
if
(localQueryResult.hasMoreElements())
{
localWTPartMaster =
(WTPartMaster)localQueryResult.nextElement();
}
if
(VERBOSE)
System.out.println(" getWTPartMasterByNumber=" +
localWTPartMaster);
return
localWTPartMaster;
}
//03. 通过WTPartMaster 返回最新版本WTPart对象
public static WTPart
getLatestPartByPartMaster(WTPartMaster paramWTPartMaster)
throws
WTException
{
Iterated
localIterated = null;
boolean bool
= false;
LatestConfigSpec localLatestConfigSpec = new
LatestConfigSpec();
QueryResult localQueryResult =
ConfigHelper.service.filteredIterationsOf(paramWTPartMaster,
localLatestConfigSpec);
if
((localQueryResult != null) && (localQueryResult.size()
<= 0))
{
ConfigSpec localConfigSpec =
ConfigHelper.service.getDefaultConfigSpecFor(WTPartMaster.class);
localQueryResult =
ConfigHelper.service.filteredIterationsOf(paramWTPartMaster,
localConfigSpec);
}
while
((localQueryResult.hasMoreElements()) && (!bool))
{
localIterated = (Iterated)localQueryResult.nextElement();
bool = localIterated.isLatestIteration();
}
if
((VERBOSE) && (localIterated != null))
System.out.println(" the latest iteration=" + localIterated.getIdentity());
return
(WTPart)localIterated;
}
//04.通过WTPartMaster 和
版本 返回
WTPart
public static WTPart
getSpecialPartByMasterAndVersion(WTPartMaster paramWTPartMaster,
String paramString)
throws
WTException
{
WTPart
localWTPart = null;
String str =
"";
QueryResult localQueryResult =
VersionControlHelper.service.allVersionsOf(paramWTPartMaster);
if
((localQueryResult != null) && (localQueryResult.size()
<= 0))
{
return null;
}
while
(localQueryResult.hasMoreElements())
{
localWTPart = (WTPart)localQueryResult.nextElement();
str =
VersionControlHelper.getVersionIdentifier(localWTPart).getValue();
if (str.equalsIgnoreCase(paramString))
return localWTPart;
}
return
null;
}
//05.零件向下所有零件列表
public static Vector getSubPartListByPart(WTPart
paramWTPart)
throws
WTException
{
Vector
localVector1 = new Vector();
Vector
localVector2 = getFirstLevelSubPartListByPart(paramWTPart, "");
for (int
i = 0; i < localVector2.size(); i++)
{
WTPart localWTPart1 = (WTPart)localVector2.elementAt(i);
if (!ObjectUtil.isPersistableInobjVector(localVector1,
localWTPart1)) {
localVector1.addElement(localWTPart1);
}
Vector localVector3 = getSubPartListByPart(localWTPart1);
for (int j = 0; j < localVector3.size(); j++)
{
WTPart localWTPart2 = (WTPart)localVector3.elementAt(j);
if (ObjectUtil.isPersistableInobjVector(localVector1,
localWTPart2))
continue;
localVector1.addElement(localWTPart2);
}
}
return
localVector1;
}
public static Vector
getTopPartListByPart(WTPart paramWTPart)
throws
WTException
{
Vector
localVector1 = new Vector();
if
(paramWTPart == null)
return null;
Vector
localVector2 = getParentPartListByPart(paramWTPart);
if
((localVector2 == null) || (localVector2.size() <= 0)) {
return null;
}
for (int
i = 0; i < localVector2.size(); i++)
{
WTPart localWTPart = (WTPart)localVector2.elementAt(i);
Vector localVector3 = getParentPartListByPart(localWTPart);
if ((localVector3 != null) && (localVector3.size() <=
0))
{
if (ObjectUtil.isPersistableInobjVector(localVector1,
localWTPart))
continue;
localVector1.addElement(localWTPart);
}
else
{
Vector localVector4 = new Vector();
localVector4 = getTopPartListByPart(localWTPart);
}
}
return
localVector1;
}
//上级零件
public static Vector
getParentPartListByPart(WTPart paramWTPart)
throws
WTException
{
Vector
localVector = new Vector();
try
{
WTPartMaster localWTPartMaster =
(WTPartMaster)paramWTPart.getMaster();
Object localObject = null;
QueryResult localQueryResult =
StructHelper.service.navigateUsedBy(localWTPartMaster, true);
while (localQueryResult.hasMoreElements())
{
WTPart localWTPart = (WTPart)localQueryResult.nextElement();
if ((ObjectUtil.isPersistableInobjVector(localVector, localWTPart))
||
(localWTPart == null)) continue;
localVector.addElement(localWTPart);
}
}
catch
(WTException localWTException)
{
localWTException.printStackTrace();
}
return
localVector;
}
public static String
getPartVersionNumber(WTPart paramWTPart)
throws
WTException
{
String str =
"";
try
{
str =
VersionControlHelper.getVersionIdentifier(paramWTPart).getValue();
}
catch
(VersionControlException localVersionControlException)
{
localVersionControlException.printStackTrace();
}
return
str;
}
//返回版本
public static String
getPartReversionNumber(WTPart paramWTPart)
throws
WTException
{
String str =
"";
try
{
str =
VersionControlHelper.getIterationIdentifier(paramWTPart).getValue();
}
catch
(VersionControlException localVersionControlException)
{
localVersionControlException.printStackTrace();
}
return
str;
}
public static WTPart getPreVersionPart(WTPart
paramWTPart)
throws
WTException
{
WTPart
localWTPart = null;
String
str1 = getPartReversionNumber(paramWTPart);
String
str2 = getPartVersionNumber(paramWTPart);
int i =
1;
if
(str2.equals("A")) {
return null;
}
try
{
QueryResult localQueryResult =
VersionControlHelper.service.allVersionsFrom(paramWTPart);
if (localQueryResult != null) {
while ((localQueryResult.hasMoreElements()) && (i !=
0))
{
localWTPart = (WTPart)localQueryResult.nextElement();
String str3 =
VersionControlHelper.getVersionIdentifier(localWTPart).getValue();
if (str3.equalsIgnoreCase(str2))
{
continue;
}
i = 0;
}
}
}
catch
(WTException localWTException)
{
localWTException.printStackTrace();
}
return
localWTPart;
}
public static Vector
getRelatedDocListByPart(WTPart paramWTPart)
throws
WTException
{
if
(paramWTPart == null)
return null;
Vector
localVector = new Vector();
QueryResult localQueryResult =
PartDocHelper.service.getAssociatedDocuments(paramWTPart);
while
((localQueryResult != null) &&
(localQueryResult.hasMoreElements()))
{
WTObject localWTObject =
(WTObject)localQueryResult.nextElement();
if ((localWTObject instanceof WTDocument))
localVector.addElement(localWTObject);
}
return
localVector;
}
public static double
getQuantityOfUsagelink(WTPartUsageLink paramWTPartUsageLink)
throws
WTException
{
Quantity
localQuantity = paramWTPartUsageLink.getQuantity();
double d =
0.0D;
if
(localQuantity != null)
d = localQuantity.getAmount();
return
d;
}
public static String
getUnitOfUsagelink(WTPartUsageLink paramWTPartUsageLink)
throws
WTException
{
Quantity
localQuantity = paramWTPartUsageLink.getQuantity();
String str =
"ea";
if
(localQuantity != null)
str = localQuantity.getUnit().toString();
return
str;
}
public static String
getContainerNameByPart(WTPart paramWTPart)
throws
WTException
{
String str =
"";
if
(paramWTPart != null)
{
WTContainer localWTContainer = paramWTPart.getContainer();
str = localWTContainer.getName();
}
return
str;
}
public static WTPartUsageLink
createUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, long
paramLong, String paramString, double paramDouble, boolean
paramBoolean)
throws
WTException
{
String str =
new Long(paramLong).toString();
if
((paramWTPart1 == null) || (paramWTPart2 == null)) {
return null;
}
WTPartUsageLink localWTPartUsageLink = null;
Vector
localVector = new Vector();
localVector
= getPartUsageLink(paramWTPart1, paramWTPart2, paramString,
paramDouble, str);
if
(localVector.size() > 0)
{
if (VERBOSE)
System.out.println("系统中已存在这样的link!!!");
localWTPartUsageLink =
(WTPartUsageLink)localVector.elementAt(0);
return localWTPartUsageLink;
}
if
(VERBOSE) {
System.out.println("创建新的link!!!");
}
if
(paramBoolean == true) {
paramWTPart1 = (WTPart)VcUtil.checkoutObject(paramWTPart1);
}
WTPartMaster localWTPartMaster =
(WTPartMaster)paramWTPart2.getMaster();
localWTPartUsageLink =
WTPartUsageLink.newWTPartUsageLink(paramWTPart1,
localWTPartMaster);
try
{
localWTPartUsageLink.setLineNumber(LineNumber.newLineNumber(paramLong));
localWTPartUsageLink.setQuantity(Quantity.newQuantity(paramDouble,
QuantityUnit.toQuantityUnit(paramString)));
if (paramBoolean == true)
{
PersistenceHelper.manager.save(localWTPartUsageLink);
if (VERBOSE) {
System.out.println("create usageLink.....");
}
}
else
{
Transaction localTransaction = new Transaction();
try
{
localTransaction.start();
PersistenceServerHelper.manager.lock(paramWTPart1,