1.工序指派资源

main
xuezhou 3 weeks ago
parent c252733fe9
commit d7a1b14b5e

@ -20,7 +20,13 @@ Require-Bundle: org.eclipse.ui,
com.teamcenter.rac.pca.kernel,
com.teamcenter.rac.pse.pca,
com.teamcenter.rac.cme.kernel,
org.apache.poi.39
org.apache.poi.39,
TcSoaAdministrationRac;bundle-version="13000.3.0",
TcSoaBomRac;bundle-version="13000.3.0",
TcSoaCommon;bundle-version="13000.3.0",
TcSoaConfigurationRac;bundle-version="13000.3.0",
TcSoaManufacturingRac;bundle-version="13000.3.0",
TcSoaStructureManagementRac;bundle-version="13000.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.sq.customization
Bundle-ActivationPolicy: lazy

@ -13,7 +13,7 @@
point="org.eclipse.ui.commands">
<command
name="【自动匹配替换工具】"
name="【自动匹配工具】"
id="com.sq.customization.commands.sampleCommand">
</command>
</extension>

@ -47,6 +47,7 @@ import com.sq.customization.util.RangChecker;
import com.sq.customization.util.RangeAdjuster;
import com.sq.customization.util.RangeCalculator;
import com.sq.customization.util.StringConditionChecker;
import com.sq.customization.util.TCUtil;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
@ -57,7 +58,9 @@ import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrProcessLine;
import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrProcessStation;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
@ -66,6 +69,7 @@ import com.teamcenter.rac.util.ButtonLayout;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
public class AutoTransToolDialog extends AbstractAIFDialog {
@ -102,10 +106,12 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
private Map<String,List<SleeveBean>> SleeveMap = new HashMap<>();//excel套筒
// private int times = 0;
private int row_num = 1;
public AutoTransToolDialog(Frame fm,InterfaceAIFComponent target,TCSession session) {
private TCComponentBOMLine workline;
public AutoTransToolDialog(Frame fm,InterfaceAIFComponent target,TCSession session,TCComponentBOMLine workline) {
super(fm);
this.target = target;
this.session = session;
this.workline = workline;
op_nodesignmap.clear();
no_load.clear();
DesignPartBeanMap.clear();
@ -513,7 +519,22 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
if(childcom instanceof TCComponentMfgBvrOperation) {
TCComponentMfgBvrOperation op = (TCComponentMfgBvrOperation) childcom;
String bl_rev_object_name = op.getProperty("bl_rev_object_name");
//先查询是否有资源,没资源的跳过
boolean iscontinue = true;
AIFComponentContext[] design_children1 = op.getChildren();
for(AIFComponentContext designchild:design_children1) {
InterfaceAIFComponent designchildcom = designchild.getComponent();
String bl_occ_type = designchildcom.getProperty("bl_occ_type");
if("MEResource".equalsIgnoreCase(bl_occ_type)) {
iscontinue = false;
break;
}
}
if(!iscontinue) {
continue;
}
if(bl_rev_object_name.contains("预紧") || bl_rev_object_name.contains("终紧")
|| bl_rev_object_name.contains("紧固")|| bl_rev_object_name.contains("拧紧")
@ -522,9 +543,16 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
AIFComponentContext[] design_children = op.getChildren();
boolean hasdesign = false;
Map<String,String> idmap = new HashMap<>();
Map<String,String> pipei_resource_map = new HashMap<>();
// Map<String,List<InterfaceAIFComponent>> resource_map = new HashMap<>();//工序下挂接的资源
for(AIFComponentContext designchild:design_children) {
InterfaceAIFComponent designchildcom = designchild.getComponent();
String bl_item_object_type = designchildcom.getProperty("bl_item_object_type");
String bl_occ_type = designchildcom.getProperty("bl_occ_type");
// if("MEResource".equalsIgnoreCase(bl_occ_type)) {
// String Resource_name = designchildcom.getProperty("bl_rev_object_name");
// resource_map.computeIfAbsent(Resource_name, key2 -> new ArrayList<>()).add(designchildcom);
// }
if("Design Part".equalsIgnoreCase(bl_item_object_type)) {
hasdesign = true;
//获取符合的数据
@ -1150,17 +1178,18 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
System.out.println("匹配标准件designid:"+designid);
if(StandardPartMap.containsKey(designid)) {
StandardPartBean stdbean = StandardPartMap.get(designid);
String headform = stdbean.getHeadform();
// String headform = stdbean.getHeadform();
String headsize = stdbean.getHeadsize();
Cell headform_cell = row.createCell(6);
headform_cell.setCellValue(headform);
Cell headsize_cell = row.createCell(7);
// Cell headform_cell = row.createCell(6);
// headform_cell.setCellValue(headform);
Cell headsize_cell = row.createCell(6);
headsize_cell.setCellValue(headsize);
String key2 = headsize+"|"+headform;
// String key2 = headsize+"|"+headform;
String key2 = headsize;
System.out.println("寻找套筒 头部尺寸|头部形式:"+key2);
if(SleeveMap.containsKey(key2)) {
System.out.println("找到匹配");
Cell all_cell = row.createCell(8);
Cell all_cell = row.createCell(7);
String all = "";
List<SleeveBean> SleeveBeans = SleeveMap.get(key2);
for(SleeveBean sleevebean:SleeveBeans) {
@ -1184,14 +1213,14 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
if(outsize.equals(inputsize)) {
System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType);
has = true;
all = all+resourcetype+"-"+resourceType;
all = all+resourcetype+"+"+resourceType;
break;
}
}
else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){
System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType);
all = all+resourcetype+"-"+resourceType;
all = all+resourcetype+"+"+resourceType;
has = true;
break;
}
@ -1208,6 +1237,10 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
}
}
all_cell.setCellValue(all);
if(all != null && all.length() > 0) {
if(!pipei_resource_map.containsKey(all))
pipei_resource_map.put(all, all);
}
}
else
System.out.println("没有找到匹配");
@ -1230,12 +1263,133 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
op_nodesignmap.put(bl_rev_object_name, op);
}
else {
// List<String> newresources = new ArrayList<>();
// for(String pipei_resource:pipei_resource_map.keySet()) {
// if(resource_map.containsKey(pipei_resource)) {
// resource_map.remove(pipei_resource);
// }
// else {
// newresources.add(pipei_resource);
// }
// }
//将不能存在的资源移除掉
// String resourceids = "";
// for(String pipei_resource:resource_map.keySet()) {
// List<InterfaceAIFComponent> bomline = resource_map.get(pipei_resource);
// for(InterfaceAIFComponent com:bomline) {
// if(com != null && com instanceof TCComponentBOMLine) {
// TCComponentBOMLine line = (TCComponentBOMLine) com;
// String resourceid = line.getProperty("bl_item_item_id");
// resourceids = resourceids +resourceid+";";
// line.cut();
// }
// }
//
// }
// if(resourceids.endsWith(";")) {
// resourceids = resourceids.substring(0,resourceids.length() - 1);
// }
((TCComponentMfgBvrOperation) childcom).window().save();
//获取工位
System.out.println(childcom+"获取工位");
List<TCComponent> result = getStation((TCComponentBOMLine)childcom);
if(result.size() > 0) {
String queryid = "";
for(TCComponent station:result) {
String stationid = station.getProperty("bl_item_item_id");
queryid = queryid + stationid+";";
}
if(queryid.endsWith(";")) {
queryid = queryid.substring(0, queryid.length()-1);
}
if(workline != null) {
Map<String,String> clause = new HashMap<>();
clause.put("item_id", queryid);
List<TCComponent> result2 = TCUtil.queryBOMStructObject(session,workline,"queryItem",clause);
if(result2 != null) {
for(TCComponent stationline:result2) {
//工位下先去除资源
// if(queryid.length() > 0) {
// Map<String,String> clause2 = new HashMap<>();
// clause2.put("object_name", queryid);
// List<TCComponent> deleteResourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause2);
// if(deleteResourceresult2 != null)
// for(TCComponent resourceline:deleteResourceresult2) {
// if(resourceline instanceof TCComponentBOMLine) {
// TCComponentBOMLine rs = (TCComponentBOMLine) resourceline;
// rs.cut();
// }
//
// }
// }
if(stationline instanceof TCComponentBOMLine) {
TCComponentBOMLine station = (TCComponentBOMLine) stationline;
for(String pipei_resource:pipei_resource_map.keySet()) {
//要放的资源到工序下
if(pipei_resource == null || pipei_resource.length() == 0)
continue;
//先判断工位下是否有此名称的资源,有的直接拿来用
Map<String,String> clause3 = new HashMap<>();
clause3.put("object_name", pipei_resource);
List<TCComponent> Resourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause3);
if(Resourceresult2.size() > 0) {
TCUtil.connectObject(session, Resourceresult2.get(0), (TCComponent)op, "MEResource");
}
else {
Map<String,String> clause22 = new HashMap<>();
clause22.put("object_name", pipei_resource);
TCComponent[] query_items = TCUtil.Generalquery2(session, "queryItem", clause22);
if(query_items != null && query_items.length > 0) {
TCComponentBOMLine newResourceline = station.add((TCComponentItem) query_items[0],null, null, false);
TCUtil.connectObject(session, newResourceline, (TCComponent)op, "MEResource");
}
else {
//创建新的item
TCComponentItem item = TCUtil.createItem(session, "", "A", "Item", pipei_resource);
TCComponentBOMLine newResourceline = station.add(item,null, null, false);
TCUtil.connectObject(session, newResourceline, (TCComponent)op, "MEResource");
String[] split = pipei_resource.split("\\+",-1);
Map<String,String> clause2 = new HashMap<>();
for(String split_value:split) {
clause2.clear();
clause2.put("object_name", split_value);
TCComponent[] tool_resource = TCUtil.Generalquery2(session, "queryItem", clause);
if(tool_resource != null && tool_resource.length > 0) {
newResourceline.add((TCComponentItem) tool_resource[0],null, null, false);
}
}
}
}
}
}
}
}
}
}
}
idmap.clear();
}
//
}
else if(childcom instanceof TCComponentMfgBvrProcessStation || childcom instanceof TCComponentMfgBvrProcessLine
|| childcom instanceof TCComponentMfgBvrPlantBOP) {
opBOMLineData(childcom,sheet);
}
@ -1279,12 +1433,20 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
}
}
if(found) {
TCComponentMfgBvrOperation oldop = op_nodesignmap.get(haskey);
AIFComponentContext[] design_children = op.getChildren();
boolean hasdesign = false;
Map<String,String> idmap = new HashMap<>();
Map<String,String> pipei_resource_map = new HashMap<>();
// Map<String,List<InterfaceAIFComponent>> resource_map = new HashMap<>();//工序下挂接的资源
for(AIFComponentContext designchild:design_children) {
InterfaceAIFComponent designchildcom = designchild.getComponent();
String bl_item_object_type = designchildcom.getProperty("bl_item_object_type");
String bl_occ_type = designchildcom.getProperty("bl_occ_type");
// if("MEResource".equalsIgnoreCase(bl_occ_type)) {
// String Resource_name = designchildcom.getProperty("bl_rev_object_name");
// resource_map.computeIfAbsent(Resource_name, key2 -> new ArrayList<>()).add(designchildcom);
// }
if("Design Part".equalsIgnoreCase(bl_item_object_type)) {
hasdesign = true;
//获取符合的数据
@ -1910,17 +2072,18 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
System.out.println("匹配标准件designid:"+designid);
if(StandardPartMap.containsKey(designid)) {
StandardPartBean stdbean = StandardPartMap.get(designid);
String headform = stdbean.getHeadform();
// String headform = stdbean.getHeadform();
String headsize = stdbean.getHeadsize();
Cell headform_cell = row.createCell(6);
headform_cell.setCellValue(headform);
Cell headsize_cell = row.createCell(7);
// Cell headform_cell = row.createCell(6);
// headform_cell.setCellValue(headform);
Cell headsize_cell = row.createCell(6);
headsize_cell.setCellValue(headsize);
String key2 = headsize+"|"+headform;
// String key2 = headsize+"|"+headform;
String key2 = headsize;
System.out.println("寻找套筒 头部尺寸|头部形式:"+key2);
if(SleeveMap.containsKey(key2)) {
System.out.println("找到匹配");
Cell all_cell = row.createCell(8);
Cell all_cell = row.createCell(7);
String all = "";
List<SleeveBean> SleeveBeans = SleeveMap.get(key2);
for(SleeveBean sleevebean:SleeveBeans) {
@ -1944,14 +2107,14 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
if(outsize.equals(inputsize)) {
System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType);
has = true;
all = all+resourcetype+"-"+resourceType;
all = all+resourcetype+"+"+resourceType;
break;
}
}
else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){
System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType);
all = all+resourcetype+"-"+resourceType;
all = all+resourcetype+"+"+resourceType;
has = true;
break;
}
@ -1968,6 +2131,10 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
}
}
all_cell.setCellValue(all);
if(all != null && all.length() > 0) {
if(!pipei_resource_map.containsKey(all))
pipei_resource_map.put(all, all);
}
}
else
System.out.println("没有找到匹配");
@ -1985,6 +2152,126 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
op_nodesignmap.remove(haskey);
}
else {
// List<String> newresources = new ArrayList<>();
// for(String pipei_resource:pipei_resource_map.keySet()) {
// if(resource_map.containsKey(pipei_resource)) {
// resource_map.remove(pipei_resource);
// }
// else {
// newresources.add(pipei_resource);
// }
// }
//将不能存在的资源移除掉
// String resourceids = "";
// for(String pipei_resource:resource_map.keySet()) {
// List<InterfaceAIFComponent> bomline = resource_map.get(pipei_resource);
// for(InterfaceAIFComponent com:bomline) {
// if(com != null && com instanceof TCComponentBOMLine) {
// TCComponentBOMLine line = (TCComponentBOMLine) com;
// String resourceid = line.getProperty("bl_item_item_id");
// resourceids = resourceids +resourceid+";";
// line.cut();
// }
// }
//
// }
// if(resourceids.endsWith(";")) {
// resourceids = resourceids.substring(0,resourceids.length() - 1);
// }
((TCComponentMfgBvrOperation) childcom).window().save();
//获取工位
System.out.println(childcom+"获取工位");
List<TCComponent> result = getStation((TCComponentBOMLine)childcom);
if(result.size() > 0) {
String queryid = "";
for(TCComponent station:result) {
String stationid = station.getProperty("bl_item_item_id");
queryid = queryid + stationid+";";
}
if(queryid.endsWith(";")) {
queryid = queryid.substring(0, queryid.length()-1);
}
if(workline != null) {
Map<String,String> clause = new HashMap<>();
clause.put("item_id", queryid);
List<TCComponent> result2 = TCUtil.queryBOMStructObject(session,workline,"queryItem",clause);
if(result2 != null) {
for(TCComponent stationline:result2) {
//工位下先去除资源
// if(queryid.length() > 0) {
// Map<String,String> clause2 = new HashMap<>();
// clause2.put("object_name", queryid);
// List<TCComponent> deleteResourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause2);
// if(deleteResourceresult2 != null)
// for(TCComponent resourceline:deleteResourceresult2) {
// if(resourceline instanceof TCComponentBOMLine) {
// TCComponentBOMLine rs = (TCComponentBOMLine) resourceline;
// rs.cut();
// }
//
// }
// }
if(stationline instanceof TCComponentBOMLine) {
TCComponentBOMLine station = (TCComponentBOMLine) stationline;
for(String pipei_resource:pipei_resource_map.keySet()) {
//要放的资源到工序下
if(pipei_resource == null || pipei_resource.length() == 0)
continue;
//先判断工位下是否有此名称的资源,有的直接拿来用
Map<String,String> clause3 = new HashMap<>();
clause3.put("object_name", pipei_resource);
List<TCComponent> Resourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause3);
if(Resourceresult2.size() > 0) {
TCUtil.connectObject(session, Resourceresult2.get(0), (TCComponent)oldop, "MEResource");
}
else {
Map<String,String> clause22 = new HashMap<>();
clause22.put("object_name", pipei_resource);
TCComponent[] query_items = TCUtil.Generalquery2(session, "queryItem", clause22);
if(query_items != null && query_items.length > 0) {
TCComponentBOMLine newResourceline = station.add((TCComponentItem) query_items[0],null, null, false);
TCUtil.connectObject(session, newResourceline, (TCComponent)oldop, "MEResource");
}
else {
//创建新的item
TCComponentItem item = TCUtil.createItem(session, "", "A", "Item", pipei_resource);
TCComponentBOMLine newResourceline = station.add(item,null, null, false);
TCUtil.connectObject(session, newResourceline, (TCComponent)oldop, "MEResource");
String[] split = pipei_resource.split("\\+",-1);
Map<String,String> clause2 = new HashMap<>();
for(String split_value:split) {
clause2.clear();
clause2.put("object_name", split_value);
TCComponent[] tool_resource = TCUtil.Generalquery2(session, "queryItem", clause);
if(tool_resource != null && tool_resource.length > 0) {
newResourceline.add((TCComponentItem) tool_resource[0],null, null, false);
}
}
}
}
}
}
}
}
}
}
}
idmap.clear();
}
@ -2458,7 +2745,7 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
tool.setInputSize(inputSize);
tool.setOutSize(outSize);
SleeveMap.computeIfAbsent(outSize+"|"+headform, key -> new ArrayList<>()).add(tool);
SleeveMap.computeIfAbsent(outSize, key -> new ArrayList<>()).add(tool);
}
else {
@ -2474,4 +2761,22 @@ public class AutoTransToolDialog extends AbstractAIFDialog {
e.printStackTrace();
}
}
private List<TCComponent> getStation(TCComponentBOMLine child){
List<TCComponent> result = null;
Map<String,String> clause = new HashMap<>();
clause.put("object_type", "MEStation");
try {
result = TCUtil.queryBOMStructObject2(session,child,"queryItem",clause);
if((result == null || result.size() == 0 )&& child.parent() != null) {
result = getStation(child.parent());
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}

@ -1,16 +1,28 @@
package com.sq.customization.handlers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.sq.customization.dialogs.AutoTransToolDialog;
import com.sq.customization.util.TCUtil;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrOperation;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOPWindow;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
public class SampleHandler extends AbstractHandler {
@ -28,18 +40,55 @@ public class SampleHandler extends AbstractHandler {
}
System.out.println(target[0].getType());
System.out.println(target[0].getClass());
if("Mfg0BvrPlantBOP".equals(target[0].getType()) || "Mfg0BvrProcessLine".equals(target[0].getType()) || "Mfg0BvrProcessStation".equals(target[0].getType())) {
new AutoTransToolDialog(app.getDesktop(),target[0],session);
// TCComponentMfgBvrPlantBOP targetline = (TCComponentMfgBvrPlantBOP) target[0];
if("Mfg0BvrPlantBOP".equals(target[0].getType()) || "Mfg0BvrProcessLine".equals(target[0].getType()) || "Mfg0BvrProcessStation".equals(target[0].getType())
) {
// Map<String,String> clause = new HashMap<>();
// clause.put("item_id", "000790;000796");
// try {
// AIFComponentContext[] comcontext = targetline.getChildren();
// for(int i = 0; i < comcontext.length; i++) {
// System.out.println(comcontext[i].getComponent().getProperty("bl_indented_title"));
// List<TCComponent> result;
// try {
// result = TCUtil.queryBOMStructObject(session,(TCComponent)target[0],"queryItem",clause);
// System.out.println("result:"+result.size());
// } catch (TCException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// } catch (Exception e) {
//
// } catch (ServiceException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
TCComponentBOPWindow bopwind;
try {
bopwind = (TCComponentBOPWindow) ((TCComponentBOMLine) target[0]).window();
TCComponent[] com = bopwind.getReferencedWindows();
TCComponentBOMLine workline = null;
if(com != null && com.length > 0 ) {
for(TCComponent c:com) {
if(c instanceof TCComponentBOMWindow) {
TCComponentBOMWindow window = (TCComponentBOMWindow) c;
TCComponentBOMLine line = window.getTopBOMLine();
if(line != null) {
System.out.println(line.getProperty("bl_indented_title"));
String bl_item_object_type = line.getTCProperty("bl_item_object_type").getStringValue();
System.out.println(bl_item_object_type);
if("MEPlant".equals(bl_item_object_type)) {
workline = line;
// TCUtil.connectObject(session, line, (TCComponent)target[0], "MEWorkArea");
}
}
}
}
}
new AutoTransToolDialog(app.getDesktop(),target[0],session,workline);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;

@ -0,0 +1,223 @@
package com.sq.customization.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCQueryClause;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.services.rac.manufacturing.DataManagementService;
import com.teamcenter.services.rac.manufacturing.StructureSearchService;
import com.teamcenter.services.rac.manufacturing._2009_10.StructureSearch.MFGSearchCriteria;
import com.teamcenter.services.rac.manufacturing._2009_10.StructureSearch.SavedQueryExpression;
import com.teamcenter.services.rac.manufacturing._2009_10.StructureSearch.SearchBySizeExpression;
import com.teamcenter.services.rac.manufacturing._2009_10.StructureSearch.SearchExpressionSet;
import com.teamcenter.services.rac.manufacturing._2009_10.StructureSearch.StructureSearchResultResponse;
import com.teamcenter.services.rac.manufacturing._2012_02.DataManagement.ConnectObjectResponse;
import com.teamcenter.services.rac.manufacturing._2012_02.DataManagement.ConnectObjectsInputData;
import com.teamcenter.services.rac.manufacturing._2012_02.DataManagement.GeneralInfo;
import com.teamcenter.services.rac.manufacturing._2012_02.DataManagement.SourceInfo;
public class TCUtil {
public static TCComponent[] Generalquery2(TCSession session,String quryname,Map<String,String> clause) throws TCException {
String[] entry_name = new String[clause.size()];
String[] values = new String[clause.size()];
TCComponentQueryType queryType = (TCComponentQueryType)session.getTypeComponent("ImanQuery");
TCComponentQuery datasetQuery = (TCComponentQuery)queryType.find(quryname);
TCQueryClause[] elements = ((TCComponentQuery)datasetQuery).describe();
int k = 0;
for(TCQueryClause element : elements)
{
//System.out.println(element.getAttributeName());
if(clause.containsKey(element.getAttributeName()))
{
//System.out.println(element.getUserEntryNameDisplay());
entry_name[k] = element.getUserEntryNameDisplay();
values[k] = clause.get(element.getAttributeName());
k++;
}
}
TCComponent[] folder = datasetQuery.execute(entry_name,values);
return folder;
}
public static TCComponentItem createItem(TCSession session,String itemid, String revid,String type, String itemname)
throws TCException
{
TCComponentItemType itemtype = (TCComponentItemType)session
.getTypeComponent(type);
if (itemid.equals("")) {
itemid = itemtype.getNewID();
}
TCComponentItem item = itemtype.create(itemid, revid, type, itemname, "", null);
return item;
}
public static void connectObject(TCSession session,TCComponent sourceObject,TCComponent targetObject,String relationType) {
DataManagementService dm = DataManagementService.getService(session);
ConnectObjectsInputData[] inputs = new ConnectObjectsInputData[1];
ConnectObjectsInputData in = new ConnectObjectsInputData();
in.targetObjects = new TCComponent[] {targetObject};
in.sourceInfo = new SourceInfo();
in.sourceInfo.sourceObjects = new TCComponent[] {sourceObject};
in.sourceInfo.additionalInfo = new GeneralInfo();
in.sourceInfo.additionalInfo.stringArrayProps = new HashMap<>();
in.sourceInfo.additionalInfo.stringArrayProps.put("relationType", new String[] {relationType});
in.sourceInfo.additionalInfo.boolProps = new HashMap<>();
in.sourceInfo.additionalInfo.boolProps.put("occTypeFromPreferenceFlag", Boolean.valueOf("1"));
inputs[0] = in;
ConnectObjectResponse conres = dm.connectObjects(inputs);
if(conres.serviceData.sizeOfPartialErrors() > 0) {
System.out.println(conres.serviceData.getPartialError(0).getErrorValues()[0].getMessage());
}
}
//多层查询
public static List<TCComponent> queryBOMStructObject(TCSession session,TCComponent topbomline,String quryname,Map<String,String> clause) throws ServiceException, TCException {
List<TCComponent> result = new ArrayList<>();
TCComponentQueryType queryType = (TCComponentQueryType)session.getTypeComponent("ImanQuery");
TCComponentQuery datasetQuery = (TCComponentQuery)queryType.find(quryname);
TCQueryClause[] elements = ((TCComponentQuery)datasetQuery).describe();
String[] entry_name = new String[clause.size()];
String[] values = new String[clause.size()];
int k = 0;
for(TCQueryClause element : elements)
{
if(clause.containsKey(element.getAttributeName()))
{
//System.out.println(element.getUserEntryNameDisplay());
entry_name[k] = element.getUserEntryNameDisplay();
values[k] = clause.get(element.getAttributeName());
k++;
}
}
StructureSearchService search = StructureSearchService.getService(session);
if(search != null){
SearchExpressionSet exp = new SearchExpressionSet();
SavedQueryExpression[] savedquery = new SavedQueryExpression[1];
SavedQueryExpression qr = new SavedQueryExpression();
qr.entries = entry_name;
qr.values = values;
qr.savedQuery = datasetQuery;
savedquery[0] = qr;
exp.savedQueryExpressions = savedquery;
SearchBySizeExpression sizeexpress = new SearchBySizeExpression();
sizeexpress.diagonalLength = false;
sizeexpress.largerThan = false;
exp.sizeSearchExpression = sizeexpress;
exp.doTrushapeRefinement = false;
exp.returnScopedSubTreesHit = false;
MFGSearchCriteria criteria = new MFGSearchCriteria();
StructureSearchResultResponse searchres = search.startSearch(new TCComponent[]{topbomline}, exp, criteria);
if(searchres.searchCursor != null)
{
System.out.println("1查询结束"+searchres.finished);
System.out.println("1查询进度"+searchres.percentComplete);
System.out.println("1查询结果"+searchres.objects.length);
query(result,search,searchres.searchCursor);
System.out.println("total:"+result.size());
search.stopSearch(searchres.searchCursor);
}
else{
System.out.println("cursor is null");
}
}
return result;
}
//单层结构查询
public static List<TCComponent> queryBOMStructObject2(TCSession session,TCComponent topbomline,String quryname,Map<String,String> clause) throws ServiceException, TCException {
List<TCComponent> result = new ArrayList<>();
TCComponentQueryType queryType = (TCComponentQueryType)session.getTypeComponent("ImanQuery");
TCComponentQuery datasetQuery = (TCComponentQuery)queryType.find(quryname);
TCQueryClause[] elements = ((TCComponentQuery)datasetQuery).describe();
String[] entry_name = new String[clause.size()];
String[] values = new String[clause.size()];
int k = 0;
for(TCQueryClause element : elements)
{
if(clause.containsKey(element.getAttributeName()))
{
//System.out.println(element.getUserEntryNameDisplay());
entry_name[k] = element.getUserEntryNameDisplay();
values[k] = clause.get(element.getAttributeName());
k++;
}
}
StructureSearchService search = StructureSearchService.getService(session);
if(search != null){
SearchExpressionSet exp = new SearchExpressionSet();
SavedQueryExpression[] savedquery = new SavedQueryExpression[1];
SavedQueryExpression qr = new SavedQueryExpression();
qr.entries = entry_name;
qr.values = values;
qr.savedQuery = datasetQuery;
savedquery[0] = qr;
exp.savedQueryExpressions = savedquery;
SearchBySizeExpression sizeexpress = new SearchBySizeExpression();
sizeexpress.diagonalLength = false;
sizeexpress.largerThan = false;
exp.sizeSearchExpression = sizeexpress;
exp.doTrushapeRefinement = false;
exp.returnScopedSubTreesHit = false;
MFGSearchCriteria criteria = new MFGSearchCriteria();
StructureSearchResultResponse searchres = search.startSearch(new TCComponent[]{topbomline}, exp, criteria);
if(searchres.searchCursor != null)
{
System.out.println("1查询结束"+searchres.finished);
System.out.println("1查询进度"+searchres.percentComplete);
System.out.println("1查询结果"+searchres.objects.length);
query2(result,search,searchres.searchCursor);
System.out.println("total:"+result.size());
search.stopSearch(searchres.searchCursor);
}
else{
System.out.println("cursor is null");
}
}
return result;
}
public static void query(List<TCComponent> result,StructureSearchService search,TCComponent searchCursor) throws ServiceException{
if(searchCursor!= null){
StructureSearchResultResponse nextres = search.nextSearch(searchCursor);
System.out.println("查询结束:"+nextres.finished);
System.out.println("查询进度:"+nextres.percentComplete);
System.out.println("查询结果:"+nextres.objects.length);
if(nextres.objects.length > 0){
result.addAll(Arrays.asList(nextres.objects));
}
if(!nextres.finished){
query(result,search,searchCursor);
}
}
}
public static void query2(List<TCComponent> result,StructureSearchService search,TCComponent searchCursor) throws ServiceException{
if(searchCursor!= null){
StructureSearchResultResponse nextres = search.nextSearch(searchCursor);
System.out.println("查询结束:"+nextres.finished);
System.out.println("查询进度:"+nextres.percentComplete);
System.out.println("查询结果:"+nextres.objects.length);
if(nextres.objects.length > 0){
result.addAll(Arrays.asList(nextres.objects));
}
}
}
}
Loading…
Cancel
Save