Commit f627f4f5 authored by hanson.yao's avatar hanson.yao

convert dxUsageLink

parent 5c0cc697
......@@ -69,7 +69,6 @@ public class IBAHelper implements Serializable, RemoteAccess {
* @throws WTException
*/
public static Hashtable getAllIBAValues(WTObject obj) throws WTException, InvocationTargetException, RemoteException {
System.out.println("=================getAllIBAValues======");
if (!RemoteMethodServer.ServerFlag) {
return (Hashtable) RemoteMethodServer.getDefault().invoke("getAllIBAValues", IBAHelper.class.getName(), null, new Class[]{WTObject.class}, new Object[]{obj});
}
......@@ -121,7 +120,7 @@ public class IBAHelper implements Serializable, RemoteAccess {
public static String getIBAStringValue(WTObject obj, String ibaName)
throws WTException {
throws WTException, InvocationTargetException {
String value = null;
String ibaClass = "wt.iba.definition.StringDefinition";
try {
......@@ -630,7 +629,13 @@ public class IBAHelper implements Serializable, RemoteAccess {
}
public static DefaultAttributeContainer getContainer(IBAHolder ibaholder) throws WTException, RemoteException {
public static DefaultAttributeContainer getContainer(IBAHolder ibaholder) throws WTException, RemoteException, InvocationTargetException {
System.out.println("getContainer=============="+RemoteMethodServer.ServerFlag);
if (!RemoteMethodServer.ServerFlag) {
System.out.println("getContainer==============1");
return (DefaultAttributeContainer) RemoteMethodServer.getDefault().invoke("getContainer", IBAHelper.class.getName(), null, new Class[]{IBAHolder.class}, new Object[]{ibaholder});
}
System.out.println("getContainer==============2");
ibaholder = IBAValueHelper.service.refreshAttributeContainerWithoutConstraints(ibaholder);
DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaholder.getAttributeContainer();
return defaultattributecontainer;
......
......@@ -3,6 +3,7 @@ package com.yonde.common;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.common.TypeIdentifierHelper;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import wt.fc.*;
import wt.fc.collections.WTValuedHashMap;
......@@ -16,12 +17,17 @@ import wt.part.PartType;
import wt.part.QuantityUnit;
import wt.part.Source;
import wt.part.WTPart;
import wt.pds.StatementSpec;
import wt.query.ArrayExpression;
import wt.query.ClassAttribute;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.session.SessionServerHelper;
import wt.type.TypedUtility;
import wt.util.WTException;
import wt.vc.VersionControlHelper;
import wt.vc.config.IteratedOrderByPrimitive;
import wt.vc.config.VersionedOrderByPrimitive;
import wt.vc.views.View;
import wt.vc.views.ViewHelper;
import wt.vc.views.ViewReference;
......@@ -31,6 +37,7 @@ import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
public class PartUtil implements RemoteAccess {
private static Logger logger = LogR.getLogger(PartUtil.class.getName());
......@@ -54,7 +61,7 @@ public class PartUtil implements RemoteAccess {
boolean enforce = SessionServerHelper.manager.setAccessEnforced(accessControlled);
try {
QuerySpec querySpec = new QuerySpec(WTPart.class);
SearchCondition searchCondition = new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, number.toUpperCase(), false);
SearchCondition searchCondition = new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, "%" + number.toUpperCase() + "%", false);
querySpec.appendWhere(searchCondition, new int[]{0});
querySpec.appendAnd();
querySpec.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{0});
......@@ -316,8 +323,87 @@ public class PartUtil implements RemoteAccess {
public static void main(String[] args) throws WTException, InvocationTargetException, RemoteException {
WTPart part = getPartByNumberAndView(args[0], args[1], false);
System.out.println("part number====>" + part.getNumber());
Hashtable hashtable = IBAHelper.getAllIBAValues(part);
System.out.println("hashtable====>" + hashtable);
}
/**
* 编号查询Part
*
* @param partNumber
* @param viewName
* @param states
* @param accessControlled
* @return
* @throws WTException
*/
public static WTPart getLatestPartByNoViewWithState(String partNumber, String viewName, List<String> states,
boolean accessControlled) throws WTException, InvocationTargetException, RemoteException {
if (!RemoteMethodServer.ServerFlag){
return (WTPart) RemoteMethodServer.getDefault().invoke("getLatestPartByNoViewWithState", PartUtil.class.getName(), null, new Class[]{String.class,String.class,List.class,boolean.class}, new Object[]{partNumber,viewName,states,accessControlled});
}
WTPart latestPart = null;
if (StringUtils.isNotBlank(partNumber)) {
boolean enforce = SessionServerHelper.manager.setAccessEnforced(accessControlled);
try {
// partNumber = partNumber.toUpperCase();
QuerySpec qs = new QuerySpec(WTPart.class);
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.EQUAL, partNumber,true),
new int[] { 0 });
qs.appendAnd();
ClassAttribute ca = new ClassAttribute(WTPart.class, "checkoutInfo.state");
String[] checkOutStates = new String[] { "c/i", "c/o" };
qs.appendWhere(new SearchCondition(ca, SearchCondition.IN, new ArrayExpression(checkOutStates)),
new int[] { 0 });
// new SearchCondition(WTPart.class, "checkoutInfo.state",
// SearchCondition.NOT_EQUAL, "wrk");
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE),
new int[] { 0 });
if (StringUtils.isNotBlank(viewName)) {
View view = ViewHelper.service.getView(viewName);
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, "view.key.id", SearchCondition.EQUAL,
view.getPersistInfo().getObjectIdentifier().getId()), new int[] { 0 });
}
if (states != null && states.size() > 0) {
qs.appendAnd();
qs.appendOpenParen();
for (int i = 0; i < states.size(); i++) {
String state = states.get(i);
if (i > 0) {
qs.appendOr();
}
SearchCondition sc = new SearchCondition(WTPart.class, WTPart.LIFE_CYCLE_STATE,
SearchCondition.EQUAL, state);
qs.appendWhere(sc, new int[] { 0 });
}
qs.appendCloseParen();
}
// Order by version iteration
new VersionedOrderByPrimitive().appendOrderBy(qs, 0, true);
new IteratedOrderByPrimitive().appendOrderBy(qs, 0, true);
//log.debug("getLatestPartByNoViewWithState qs : " + qs);
QueryResult result = PersistenceHelper.manager.find((StatementSpec) qs);
if (result != null && result.size() > 0) {
latestPart = (WTPart) result.nextElement();
}
} finally {
SessionServerHelper.manager.setAccessEnforced(enforce);
}
}
return latestPart;
}
}
package com.yonde.common;
import com.yonde.part.vo.DxSourceUsageLink;
import org.apache.commons.lang.StringUtils;
import wt.doc.WTDocument;
import wt.fc.*;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.*;
import wt.util.WTException;
import wt.util.WTRuntimeException;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
/**
* Created on 2022/12/26
* usage link tools
*
* @author
*/
public class UsageLinkUtil implements RemoteAccess {
/**
* 依据父子件获取UsageLinks
*
* @param parentPart
* @return
* @throws WTException
*/
public static List getUsageLinks(WTPart parentPart) throws WTException, InvocationTargetException, RemoteException {
System.out.println("UsageLinkUtil getUsageLinks start...");
if (!RemoteMethodServer.ServerFlag) {
return (List<WTPartUsageLink>) RemoteMethodServer.getDefault().invoke("getUsageLinks", UsageLinkUtil.class.getName(), null, new Class[]{WTPart.class}, new Object[]{parentPart});
}
System.out.println("UsageLinkUtil getUsageLinks ===============1");
List<WTPartUsageLink> links = new ArrayList<WTPartUsageLink>();
if (parentPart == null) {
return links;
}
System.out.println("UsageLinkUtil getUsageLinks ===============2");
QueryResult queryresult = WTPartHelper.service.getUsesWTPartMasters(parentPart);
System.out.println("UsageLinkUtil getUsageLinks ===============3");
while (queryresult.hasMoreElements()) {
System.out.println("UsageLinkUtil getUsageLinks ===============4 in....");
links.add((WTPartUsageLink) queryresult.nextElement());
}
System.out.println("getUsageLinks size:" + links.size());
return links;
}
public static void main(String[] args) throws WTException, InvocationTargetException, RemoteException {
WTPart parent = (WTPart) getWTObjectByOid(args[0]);
System.out.println("part number:" + parent.getNumber());
List<WTPartUsageLink> usageLinks = getUsageLinks(parent);
System.out.println("===usageLinks====size:" + usageLinks.size());
List<DxSourceUsageLink> links = new ArrayList<DxSourceUsageLink>();
for (WTPartUsageLink link : usageLinks) {
DxSourceUsageLink dxUsageLink = new DxSourceUsageLink();
dxUsageLink.setCreateTime(DateTimeUtil.timeStampToString(link.getCreateTimestamp()));
dxUsageLink.setModifyTime(DateTimeUtil.timeStampToString(link.getModifyTimestamp()));
Quantity qt = link.getQuantity();
dxUsageLink.setAmount(String.valueOf(qt.getAmount()));
dxUsageLink.setUnit(qt.getUnit().toString());
dxUsageLink.setId(PartUtil.getWTObjectOid(link));
dxUsageLink.setSourceId(args[0]);
WTPartMaster uses = (WTPartMaster) link.getUses();
WTPart child = PartUtil.getLatestPartByNoViewWithState(uses.getNumber(), parent.getViewName(), null, false);
dxUsageLink.setTargetId(PartUtil.getWTObjectOid(child));
dxUsageLink.setSourceId(PartUtil.getWTObjectOid(parent));
links.add(dxUsageLink);
}
System.out.println("links size:" + links.size());
System.out.println(links.toString());
}
/**
* 根据文档oid获取文档
*
* @param oid
* @return
*/
public static WTObject getWTObjectByOid(String oid) throws InvocationTargetException, RemoteException {
if (!RemoteMethodServer.ServerFlag){
return (WTObject) RemoteMethodServer.getDefault().invoke("getWTObjectByOid", UsageLinkUtil.class.getName(), null, new Class[]{String.class}, new Object[]{oid});
}
if (StringUtils.isEmpty(oid)) {
return null;
}
ReferenceFactory referencefactory = new ReferenceFactory();
WTReference reference = null;
try {
reference = referencefactory.getReference(oid);
} catch (WTException e) {
reference = null;
}
Persistable persistable;
if (reference == null) {
return null;
} else {
try {
persistable = reference.getObject();
} catch (WTRuntimeException e) {
persistable = null;
}
}
if (persistable != null) {
if (persistable instanceof WTDocument) {
return (WTDocument) persistable;
} else if (persistable instanceof WTPart) {
return (WTPart) persistable;
}
}
return null;
}
}
......@@ -13,4 +13,10 @@ public class PartController {
public Object getPartByNumber(@RequestParam String number, @RequestParam String view) throws Exception {
return PartService.getPartByNumber(number, view);
}
@GetMapping(value = "/links")
public Object getUsageLinks(@RequestParam String oid) throws Exception {
System.out.println("PartController getUsageLinks start...");
return PartService.getUsageLinks(oid);
}
}
......@@ -3,20 +3,27 @@ package com.yonde.part.service;
import com.yonde.common.DateTimeUtil;
import com.yonde.common.IBAHelper;
import com.yonde.common.PartUtil;
import com.yonde.common.UsageLinkUtil;
import com.yonde.part.vo.DxPart;
import com.yonde.part.vo.DxSourceUsageLink;
import org.springframework.stereotype.Service;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.fc.ReferenceFactory;
import wt.org.WTUser;
import wt.part.Quantity;
import wt.part.WTPart;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;
import wt.type.ClientTypedUtility;
import wt.util.WTException;
import wt.vc.wip.WorkInProgressHelper;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
@Service
......@@ -31,10 +38,10 @@ public class PartService {
Hashtable hashtable = IBAHelper.getAllIBAValues(wtPart);
System.out.println("-----getPartByNumber----b");
if (wtPart != null) {
WTUser creat = ((WTUser) wtPart.getCreator().getObject());
dxPart.setCreator(String.format("%s(%s)", creat.getFullName(), creat.getName()));
WTUser modify = ((WTUser) wtPart.getModifier().getObject());
dxPart.setModifier(String.format("%s(%s)", modify.getFullName(), modify.getName()));
//WTUser creat = ((WTUser) wtPart.getCreator().getObject());
dxPart.setCreator(String.format("%s(%s)", wtPart.getCreatorFullName(), wtPart.getCreatorName()));
//WTUser modify = ((WTUser) wtPart.getModifier().getObject());
//dxPart.setModifier(String.format("%s(%s)", modify.getFullName(), modify.getName()));
System.out.println("-----getPartByNumber----1");
dxPart.setName(wtPart.getName());
dxPart.setNumber(wtPart.getNumber());
......@@ -77,8 +84,50 @@ public class PartService {
}
dxPart.setVersion(wtPart.getVersionIdentifier().getValue());
dxPart.setIteration(wtPart.getIterationIdentifier().getValue());
dxPart.setDynamicAttrs(hashtable);
//dxPart.setDynamicAttrs(hashtable);
}
return dxPart;
}
/**
* @param oid
* @return
* @throws WTException
* @throws RemoteException
* @throws InvocationTargetException
*/
public static List<DxSourceUsageLink> getUsageLinks(String oid) throws WTException, RemoteException, InvocationTargetException {
System.out.println("getUsageLinks=============1");
List<DxSourceUsageLink> links = new ArrayList<DxSourceUsageLink>();
WTPart parent = (WTPart) UsageLinkUtil.getWTObjectByOid(oid);
System.out.println("getUsageLinks=============2");
System.out.println("part is null:" + parent == null);
System.out.println("part number:" + parent.getNumber());
List<WTPartUsageLink> usageLinks = UsageLinkUtil.getUsageLinks(parent);
System.out.println("usageLinks size:" + usageLinks.size());
for (WTPartUsageLink link : usageLinks) {
DxSourceUsageLink dxUsageLink = new DxSourceUsageLink();
dxUsageLink.setModifyTime(DateTimeUtil.timeStampToString(link.getModifyTimestamp()));
dxUsageLink.setCreateTime(DateTimeUtil.timeStampToString(link.getCreateTimestamp()));
Quantity qt = link.getQuantity();
dxUsageLink.setId(PartUtil.getWTObjectOid(link));
dxUsageLink.setAmount(String.valueOf(qt.getAmount()));
dxUsageLink.setUnit(qt.getUnit().toString());
dxUsageLink.setSourceId(oid);
WTPartMaster uses = (WTPartMaster)link.getUses();
WTPart child = PartUtil.getLatestPartByNoViewWithState(uses.getNumber(), parent.getViewName(), null, false);
dxUsageLink.setTargetId(PartUtil.getWTObjectOid(child));
dxUsageLink.setSourceId(PartUtil.getWTObjectOid(parent));
links.add(dxUsageLink);
}
return links;
}
public static void main(String[] args) throws WTException, InvocationTargetException, RemoteException {
List<DxSourceUsageLink> usageLinks = getUsageLinks(args[0]);
System.out.println(usageLinks.size());
}
}
......@@ -4,6 +4,7 @@ import org.apache.log4j.Logger;
import wt.log4j.LogR;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
......@@ -36,10 +37,23 @@ public class DxPart implements Serializable {
//todo dynamicAttrs subTypeDisplayName 无法获取
private Map<String, Object> dynamicAttrs;
/**
* usageLinks bom link
*/
private List<DxSourceUsageLink> sourceUsageLinks;
public DxPart() {
}
public List<DxSourceUsageLink> getSourceUsageLinks() {
return sourceUsageLinks;
}
public void setSourceUsageLinks(List<DxSourceUsageLink> sourceUsageLinks) {
this.sourceUsageLinks = sourceUsageLinks;
}
public String getIteration() {
return iteration;
}
......
package com.yonde.part.vo;
import java.util.Map;
/**
* Created on 2022/12/26
*
* @author
*/
public class DxSourceUsageLink {
private String id;
private String unit;
private String amount;
private DxPart target;
private String targetId;
private String sourceId;
private String createTime;
private String modifyTime;
private String dxClassname = "com.yonde.dcs.xbom.common.entity.vo.DxUsageLinkVO";
private String subTypeDisplayName;
private Map<String, String> dynamicAttrs;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public DxPart getTarget() {
return target;
}
public void setTarget(DxPart target) {
this.target = target;
}
public String getTargetId() {
return targetId;
}
public void setTargetId(String targetId) {
this.targetId = targetId;
}
public String getSourceId() {
return sourceId;
}
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getModifyTime() {
return modifyTime;
}
public void setModifyTime(String modifyTime) {
this.modifyTime = modifyTime;
}
public String getDxClassname() {
return dxClassname;
}
public void setDxClassname(String dxClassname) {
this.dxClassname = dxClassname;
}
public String getSubTypeDisplayName() {
return subTypeDisplayName;
}
public void setSubTypeDisplayName(String subTypeDisplayName) {
this.subTypeDisplayName = subTypeDisplayName;
}
public Map<String, String> getDynamicAttrs() {
return dynamicAttrs;
}
public void setDynamicAttrs(Map<String, String> dynamicAttrs) {
this.dynamicAttrs = dynamicAttrs;
}
@Override
public String toString() {
return "DxSourceUsageLink{" +
"id='" + id + '\'' +
", unit='" + unit + '\'' +
", amount='" + amount + '\'' +
", target=" + target +
", targetId='" + targetId + '\'' +
", sourceId='" + sourceId + '\'' +
", createTime='" + createTime + '\'' +
", modifyTime='" + modifyTime + '\'' +
", dxClassname='" + dxClassname + '\'' +
", subTypeDisplayName='" + subTypeDisplayName + '\'' +
", dynamicAttrs=" + dynamicAttrs +
'}';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment