IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Teamcenter: RAC开发 -> 正文阅读

[开发工具]Teamcenter: RAC开发

前言

Teamcenter(下面简称TC)的RAC开发,指的是TC的胖客户端开发。
本文将介绍如何通过plugin in project项目实现对TC胖客户端的修改。

工具:
	TC12(安装在虚拟机里),
	eclipse

一、环境搭建(Target Platform)

1、合并TC和Eclipse的plugins

将【TC下的plugins文件夹】和【eclipse下的plugins文件夹】都复制并合并到一个新的文件夹里,文件位置参考如下

TC:			 D:\Siemens\Teamcenter12\portal\plugins
eclipse:	 C:\eclipse\plugins

合并后:
在这里插入图片描述

2、eclipse导入plugins并创建Target Platform

将上面合并得到的plugins文件夹导入eclipse并创建Target Platform ,文字步骤如下

打开eclipse -> Window -> Preferce -> Plugin-in Development -> Target Platform -> add

在这里插入图片描述

-> 默认选择Nothing:…选项 在这里插入图片描述

-> 起名 -> add在这里插入图片描述

-> 选择Directory在这里插入图片描述
-> 找到tc与eclipse合并好的plugins文件夹 -> next
在这里插入图片描述

-> finish
在这里插入图片描述

在这里插入图片描述

-> 选中新建好的Target Platform -> Apply and close在这里插入图片描述

二、搭建Plugin-in Project项目

1、new一个Plugin-in Project项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、生成plugin.xml文件

打开项目,双击MANIFEST.MF文件 -> Extensions -> Add,生成plugin.xml文件
在这里插入图片描述
在这里插入图片描述
然后会发现项目内新增了一个plugin.xml文件
在这里插入图片描述
plugin.xml文件主要用来配置关于客户端菜单栏上面的东西,如
在这里插入图片描述

3、编写plugin.xml基础配置

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

	<extension point="org.eclipse.ui.menus">
	
		<menuContribution allPopups="false"
			locationURI="menu:org.eclipse.ui.main.menu">
			<menu id="be" label="程序入口">
				
				<command commandId="lov" id="lov"
					label="根据bom树生成报表">
				</command>
				
			</menu>
   		</menuContribution>
	
	</extension>


	<extension point="org.eclipse.ui.commands">
	
		<command
	    	id="lov"
	    	name="根据bom树生成报表">
		</command>
	
	</extension>



	<extension point="org.eclipse.ui.handlers">
	
		<handler
	        class="domain.MyHandler"
	        commandId="lov">
		</handler>
	
	</extension>

</plugin>

4、导入TC进行RAC开发的核心依赖包

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

TC进行RAC开发必需的7个核心依赖包:
	com.teamcenter.rac.kernel;
	com.teamcenter.rac.common;
	com.teamcenter.rac.tcapps;
	com.teamcenter.rac.util;
	com.teamcenter.rac.external;
	com.teamcenter.rac.aifrcp;
	com.teamcenter.rac.neva;

三、编写代码

1、创建一个类,继承AbstractHandler抽象类

在这里插入图片描述

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

public class MyHandler extends AbstractHandler{

	@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		// TODO Auto-generated method stub
		return null;
	}

}

2、编码

RAC开发的程序入口就是execute方法,可以根据需求在execute方法里进行编码。

四、RAC开发例子

1、需求

遍历TC的一个BOM树,将BOM树里包含的零组件以及零组件版本的一些信息打印到一个excle文件里,并将该excle文件以规范关系挂在顶层BomLine所在的零组件版本下。

2、程序包结构

在这里插入图片描述

3、代码实现

plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

	<extension point="org.eclipse.ui.menus">
	
		<menuContribution allPopups="false"
			locationURI="menu:org.eclipse.ui.main.menu">
			<menu id="be" label="程序入口">
				
				<command commandId="lov" id="lov"
					label="根据bom树生成报表">
				</command>
				
			</menu>
   		</menuContribution>
	
	</extension>


	<extension point="org.eclipse.ui.commands">
	
		<command
	    	id="lov"
	    	name="根据bom树生成报表">
		</command>
	
	</extension>



	<extension point="org.eclipse.ui.handlers">
	
		<handler
	        class="domain.MyHandler"
	        commandId="lov">
		</handler>
	
	</extension>

</plugin>

ItemUtil.java

package util;

import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;

public class ItemUtil {
	/**
	 * @函数功能:通过ItemRevision获得默认版本规则的BOMLine和BOMWindow @输入参数:
	 * @param revision 某版本
	 * @return BOMLine , BOMLine.window()可获取BOMWindow @注意: 使用完BOMLine后请关闭BOMWindow
	 */
	public static TCComponentBOMLine getBOMLine(TCComponentItemRevision revision, TCSession session) {
		TCComponentBOMLine bomLine = null;
		try {
			TCComponentType tccomponentType = session.getTypeComponent("BOMWindow");
			if (tccomponentType != null && tccomponentType instanceof TCComponentBOMWindowType) {
				TCComponentBOMWindowType bomwindowType = (TCComponentBOMWindowType) tccomponentType;
				TCComponentBOMWindow bomwindow = bomwindowType.create(null); // 默认版本规则
				if (bomwindow != null) {
					bomLine = bomwindow.setWindowTopLine(null, revision, null, null);
				} else {
					System.out.println("bomwindow == null");
				}
			} else {
				System.out.println(
						"tccomponentType == null || (tccomponentType instanceof TCComponentBOMWindowType == false)");
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return bomLine;
	}

	/**
	 * @函数功能:根据item_id和Item类型查询单个Item(TC12存在允许不同类型的Item具有相同的item_id的情况) @输入参数: @param
	 *                                                                  itemId
	 *                                                                  要查询的Item的ID
	 * @param itemType 要查询的ItemID的类型
	 * @param session  客户端会话 @返回输出:
	 * @return 查询到的Item
	 */
	public static TCComponentItem querySingleItem(String itemId, String itemType, TCSession session) {
		try {
			TCComponentType compType = session.getTypeComponent(itemType);
			if (compType != null && compType instanceof TCComponentItemType) {
				TCComponentItemType TCType = (TCComponentItemType) compType;
				TCComponentItem[] items = TCType.findItems(itemId);
				if (items != null && items.length > 0) {
					for (int i = 0; i < items.length; i++) {
						String type = items[i].getType();
						if (type.equals(itemType)) {
							return items[i];
						}
					}
				} else {
					System.out.println("items == null || items.length <= 0");
				}
			} else {
				System.out.println("compType == null || (compType instanceof TCComponentItemType == false)");
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * @函数功能:创建数据集 @输入参数:
	 * @param dtType  数据集类型
	 * @param dtName  数据集名称
	 * @param dtDesc  数据集描述
	 * @param session 客户端会话,根据需要可以删除并使用全局会话
	 */
	public static TCComponentDataset createDataset(String dtType, String dtName, String dtDesc, TCSession session) {
		TCComponentDataset dataset = null;
		try {
			TCComponentType tctype = session.getTypeComponent(dtType);
			if (tctype != null && tctype instanceof TCComponentDatasetType) {
				TCComponentDatasetType tcDtType = (TCComponentDatasetType) tctype;
				dataset = tcDtType.create(dtName, dtDesc, dtType);
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return dataset;
	}
}

ExcelUtil.java

package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelUtil {
	/**
	 * @函数功能:在操作系统的临时目录中创建一个名称不重复的文件夹 @返回输出:
	 * @return 返回创建出的文件夹的路径,返回的路径结尾包含目录分隔符"\\"
	 */
	public static String createTempDir() {
		String dir = "";
		String tempDir = System.getProperty("java.io.tmpdir");
		Date date = new Date();
		long time = date.getTime();
		if (tempDir.endsWith("\\")) {
			dir = tempDir + time + "\\";
		} else {
			dir = tempDir + "\\" + time + "\\";
		}
		System.out.println("最终的dir == " + dir);
		File file = new File(dir);
		if (!file.exists()) {
			boolean isOk = file.mkdirs();
			if (isOk) {
				System.out.println("文件目录创建成功!");
			} else {
				System.out.println("文件目录创建失败!");
			}
		} else {
			System.out.println(dir + "目录已存在!");
		}
		return dir;
	}

	/**
	 * @函数功能:将一个工作表,生成并写入到一个物理文件中 @输入参数:
	 * @param xwb      某工作表
	 * @param filePath 需要写入到的物理文件路径
	 */
	public static void writeWBToFile(XSSFWorkbook xwb, String filePath) {

		try {

			FileOutputStream fos = new FileOutputStream(filePath);

			xwb.write(fos);

			fos.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 在指定sheet页指定row和指定cell设置指定value
	 * 
	 * @param sheet
	 * @param row
	 * @param cell
	 * @param value
	 */
	public static void setCellValue(XSSFSheet sheet, int row, int cell, String value) {

		XSSFRow myRow = sheet.getRow(row);

		if (myRow == null) {

			myRow = sheet.createRow(row);
		}

		XSSFCell myCell = myRow.getCell(cell);

		if (myCell == null) {

			myCell = myRow.createCell(cell);
		}

		myCell.setCellType(XSSFCell.CELL_TYPE_STRING);
		myCell.setCellValue(value);
	}
	
	/**
	 * @函数功能:根据一个Excel的文件路径和Sheet页的索引获取到此Excel指定的Sheet页 @输入参数:
	 * @param excelFilePath Excel文件路径
	 * @param sheetIndex    要获取的Sheet页的索引
	 */
	public static XSSFSheet getExcelSheetFromFilePath(String excelFilePath, int sheetIndex) {

		try {
			File file = new File(excelFilePath);
			FileInputStream fis = new FileInputStream(file);
			XSSFWorkbook xwb = new XSSFWorkbook(fis);
			XSSFSheet sheet = xwb.getSheetAt(sheetIndex);
			fis.close();
			return sheet;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
}

ItemInfo.java

package bean;
/**
 * 用来存储itemRevision和bomline的一些属性
 * @author LIDESEN
 *
 */
public class ItemInfo {
	private String item_id = "";
	private String object_name = "";
	private String object_desc = "";
	private String bl_sequance_no = "";
	private String bl_uom = "";

	public ItemInfo() {
		super();
	}

	public ItemInfo(String item_id, String object_name, String object_desc, String bl_sequance_no, String bl_uom) {
		super();
		this.item_id = item_id;
		this.object_name = object_name;
		this.object_desc = object_desc;
		this.bl_sequance_no = bl_sequance_no;
		this.bl_uom = bl_uom;
	}

	public String getItem_id() {
		return item_id;
	}

	public void setItem_id(String item_id) {
		this.item_id = item_id;
	}

	public String getObject_name() {
		return object_name;
	}

	public void setObject_name(String object_name) {
		this.object_name = object_name;
	}

	public String getObject_desc() {
		return object_desc;
	}

	public void setObject_desc(String object_desc) {
		this.object_desc = object_desc;
	}

	public String getBl_sequance_no() {
		return bl_sequance_no;
	}

	public void setBl_sequance_no(String bl_sequance_no) {
		this.bl_sequance_no = bl_sequance_no;
	}

	public String getBl_uom() {
		return bl_uom;
	}

	public void setBl_uom(String bl_uom) {
		this.bl_uom = bl_uom;
	}

	@Override
	public String toString() {
		return "ItemInfo [item_id=" + item_id + ", object_name=" + object_name + ", object_desc=" + object_desc
				+ ", bl_sequance_no=" + bl_sequance_no + ", bl_uom=" + bl_uom + "]";
	}

}

MyHandler.java

package domain;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.sun.mail.handlers.message_rfc822;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

import bean.ItemInfo;
import util.ExcelUtil;
import util.ItemUtil;

/**
 * 根据TC上配置的首选项,获取TC上的BOM树信息,打印到一个报表上,创建一个数据集,将数据集放到顶层bomline所在的itemrevision下,并将报表上传到该数据集里
 * 
 * @author LIDESEN
 *
 */
public class MyHandler extends AbstractHandler {
	private static AbstractAIFUIApplication app = null;
	private static TCSession session = null;
	private static Logger logger = null;
	List<ItemInfo> list = new ArrayList<ItemInfo>();

	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		// 初始化日志模块
		logger = getLogger();
		// 初始化tc的当前应用程序
		app = AIFUtility.getCurrentApplication();
		// 获取session
		session = (TCSession) app.getSession();
		// 获取首选项服务
		TCPreferenceService preferenceService = session.getPreferenceService();

		/**
		 * 通过鼠标选中来获取bom树
		 */
		/*
		InterfaceAIFComponent com = app.getTargetComponent();
		if (com != null) {
			if (com instanceof TCComponentItemRevision) {
				TCComponentItemRevision itemRevision = (TCComponentItemRevision) com;
				// 通过零组件版本获取bomeline对象,该对象也是bom树的底层bomeline对象
				TCComponentBOMLine topBomLine = ItemUtil.getBOMLine(itemRevision, session);
				// 将顶级bomline所在的itemRevidion和bomline一些属性通过过javabean保存到集合里
				try {
					list.add(new ItemInfo(itemRevision.getProperty("item_id"), itemRevision.getProperty("object_name"),
							itemRevision.getProperty("object_desc"), topBomLine.getProperty("bl_sequance_no"),
							topBomLine.getProperty("bl_uom")));
					// 获取到bom树下的所有bomline对象
					AIFComponentContext[] bomLines = topBomLine.getChildren();
					for (int i = 0; i < bomLines.length; i++) {
						InterfaceAIFComponent bomline = bomLines[i].getComponent();
						if (bomline instanceof TCComponentBOMLine) {
							TCComponentBOMLine bl = (TCComponentBOMLine) bomline;
							// 通过bomline获取到revision对象
							TCComponentItemRevision itemRevision2 = ((TCComponentBOMLine) bl).getItemRevision();
							// 将bomline所在的itemRevidion和bomline一些属性通过过javabean保存到集合里
							list.add(new ItemInfo(itemRevision2.getProperty("item_id"),
									itemRevision2.getProperty("object_name"), itemRevision2.getProperty("object_desc"),
									bl.getProperty("bl_sequence_no"), bl.getProperty("bl_uom")));
							// 递归遍历bom树
							recursion(bl);
						}
					}
					// 获取模板excle文件sheet对象
					String exclePath = "C:\\excel\\bomMessage.xlsx";
					XSSFSheet sheet = ExcelUtil.getExcelSheetFromFilePath(exclePath, 0);
					if (sheet != null) {
						//将list数据打印到excel文件里。 外循环是获取excle模板的row对象;
						//由于excle模板从第2行开始,所以需要for循环索引从1开始;若要遍历到list集合结尾,则list.size() + 1。
						for (int i = 1; i < list.size() + 1; i++) {
							// 集合元素的索引从0开始,所以下面是list.get(i - 1) 而不是list.get(i)
							ItemInfo itemInfo = list.get(i - 1);
							// 内循环是获取cell对象并设置cell的值
							for (int j = 0; j < 6; j++) {
								if (j == 0) {
									// 序号
									ExcelUtil.setCellValue(sheet, i, j, i + "");
								} else if (j == 1) {
									// id
									ExcelUtil.setCellValue(sheet, i, j, itemInfo.getItem_id());
								} else if (j == 2) {
									// 名称
									ExcelUtil.setCellValue(sheet, i, j, itemInfo.getObject_name());
								} else if (j == 3) {
									// 描述
									ExcelUtil.setCellValue(sheet, i, j, itemInfo.getObject_desc());
								} else if (j == 4) {
									ExcelUtil.setCellValue(sheet, i, j, itemInfo.getBl_sequance_no());
								} else if (j == 5) {
									ExcelUtil.setCellValue(sheet, i, j, itemInfo.getBl_uom());
								}
							}
						}
						// 得到sheet的工作表
						XSSFWorkbook workbook = sheet.getWorkbook();
						// 获取系统临时目录路径
						String tempDir = ExcelUtil.createTempDir();
						// 创建excel文件导出路径
						String exortPath = tempDir + itemRevision.getProperty("object_name") + "信息表.xlsx";
						// 将excel的sheet页的工作表并保存到本地物理路径下
						ExcelUtil.writeWBToFile(workbook, exortPath);
						// 在顶层bomline下创建数据集
						TCComponentDataset dataset = ItemUtil.createDataset("MSExcelX",
								itemRevision.getProperty("object_name") + "信息表", "", session);
						// 将excle文件添加到数据集里
						dataset.setFiles(new String[] { exortPath }, new String[] { "excel" });
						// 以规范关系将数据集挂到顶级bomline所在的itemRevision下
						itemRevision.add("IMAN_specification", dataset);
						MessageBox.post("恭喜,报表生成成功!", "提示", MessageBox.INFORMATION);

					} else {
						loginfo("sheet页为空!");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		} else {
			MessageBox.post("请选中bom树的顶层零组件版本!", "错误", MessageBox.ERROR);
		}
		*/
		
		/**
		 * 通过首选项存储顶层bomline所在的零组件id来获取bom树
		 */
		if (preferenceService != null) {
			// 获取首选项里的值
			String[] preValue = preferenceService.getStringValues("my_topBom_id");
			if (preValue != null && preValue.length > 0) {
				// 由于我在首选项配置的值只有一个itemId,所以直接取值
				String itemId = preValue[0];
				// 通过零组件id获取到零组件对象Item
				TCComponentItem item = ItemUtil.querySingleItem(itemId, "Item", session);
				if (item != null) {
					try {
						// 通过零组件对象获取到零组件版本对象ItemRevision
						TCComponentItemRevision itemRevision = item.getLatestItemRevision();
						// 通过零组件版本获取bomeline对象,该对象也是bom树的底层bomeline对象
						TCComponentBOMLine topBomLine = ItemUtil.getBOMLine(itemRevision, session);
						// 将顶级bomline所在的itemRevidion和bomline一些属性通过过javabean保存到集合里
						list.add(new ItemInfo(itemRevision.getProperty("item_id"),
								itemRevision.getProperty("object_name"), itemRevision.getProperty("object_desc"),
								topBomLine.getProperty("bl_sequance_no"), topBomLine.getProperty("bl_uom")));
						// 获取到bom树下的所有bomline对象
						AIFComponentContext[] bomLines = topBomLine.getChildren();
						for (int i = 0; i < bomLines.length; i++) {
							InterfaceAIFComponent bomline = bomLines[i].getComponent();
							if (bomline instanceof TCComponentBOMLine) {
								TCComponentBOMLine bl = (TCComponentBOMLine) bomline;
								// 通过bomline获取到revision对象
								TCComponentItemRevision itemRevision2 = ((TCComponentBOMLine) bl).getItemRevision();
								// 将bomline所在的itemRevidion和bomline一些属性通过过javabean保存到集合里
								list.add(new ItemInfo(itemRevision2.getProperty("item_id"),
										itemRevision2.getProperty("object_name"),
										itemRevision2.getProperty("object_desc"),
										itemRevision2.getProperty("bl_sequance_no"),
										itemRevision2.getProperty("bl_uom")));
								// 递归遍历bom树
								recursion(bl);
							}
						}
						// 获取模板excle文件sheet对象
						String exclePath = "C:\\excel\\bomMessage.xlsx";
						XSSFSheet sheet = ExcelUtil.getExcelSheetFromFilePath(exclePath, 0);
						if (sheet != null) {
							/*
							 * 将list数据打印到excel文件里。 外循环是获取excle模板的row对象;
							 * 由于excle模板从第2行开始,所以需要for循环索引从1开始;若要遍历到list集合结尾,则list.size() + 1。
							 */
							for (int i = 1; i < list.size() + 1; i++) {
								// 集合元素的索引从0开始,所以下面是list.get(i - 1) 而不是list.get(i)
								ItemInfo itemInfo = list.get(i - 1);
								// 内循环是获取cell对象并设置cell的值
								for (int j = 0; j < 6; j++) {
									if (j == 0) {
										// 序号
										ExcelUtil.setCellValue(sheet, i, j, i + "");
									} else if (j == 1) {
										// id
										ExcelUtil.setCellValue(sheet, i, j, itemInfo.getItem_id());
									} else if (j == 2) {
										// 名称
										ExcelUtil.setCellValue(sheet, i, j, itemInfo.getObject_name());
									} else if (j == 3) {
										// 描述
										ExcelUtil.setCellValue(sheet, i, j, itemInfo.getObject_desc());
									} else if (j == 4) {
										ExcelUtil.setCellValue(sheet, i, j, itemInfo.getBl_sequance_no());
									} else if (j == 5) {
										ExcelUtil.setCellValue(sheet, i, j, itemInfo.getBl_uom());
									}
								}
							}
							// 得到sheet的工作表
							XSSFWorkbook workbook = sheet.getWorkbook();
							// 获取系统临时目录路径
							String tempDir = ExcelUtil.createTempDir();
							// 创建excel文件导出路径
							String exortPath = tempDir + itemRevision.getProperty("object_name") + "信息表.xlsx";
							// 将excel的sheet页的工作表并保存到本地物理路径下
							ExcelUtil.writeWBToFile(workbook, exortPath);
							// 在顶层bomline下创建数据集
							TCComponentDataset dataset = ItemUtil.createDataset("MSExcelX",
									itemRevision.getProperty("object_name") + "信息表", "", session);
							// 将excle文件添加到数据集里
							dataset.setFiles(new String[] { exortPath }, new String[] { "excel" });
							// 以规范关系将数据集挂到顶级bomline所在的itemRevision下
							itemRevision.add("IMAN_specification", dataset);
							MessageBox.post("恭喜,报表生成成功!", "提示", MessageBox.INFORMATION);
						} else {
							loginfo("sheet页为空!");
						}
					} catch (TCException e) {
						e.printStackTrace();
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					loginfo("获取零组件对象失败!");
				}
			} else {
				loginfo("获取首选项失败!");
			}
		} else {
			loginfo("获取首选项服务失败!");
		}
		return null;
	}

	// 递归遍历bom树,并把bom相关信息添加到集合里
	public void recursion(TCComponentBOMLine bomLine) throws Exception {
		// 获取到bom树下的所有bomline对象
		AIFComponentContext[] bomLines = bomLine.getChildren();
		for (int i = 0; i < bomLines.length; i++) {
			InterfaceAIFComponent bomline = bomLines[i].getComponent();
			if (bomline instanceof TCComponentBOMLine) {
				TCComponentBOMLine bl = (TCComponentBOMLine) bomline;
				// 通过bomline获取到revision对象
				TCComponentItemRevision itemRevision2 = ((TCComponentBOMLine) bl).getItemRevision();
				// 将bomline所在的itemRevidion和bomline一些属性通过过javabean保存到集合里
				ItemInfo itemInfo = new ItemInfo(itemRevision2.getProperty("item_id"),
						itemRevision2.getProperty("object_name"), itemRevision2.getProperty("object_desc"),
						itemRevision2.getProperty("bl_sequance_no"), itemRevision2.getProperty("bl_uom"));
				list.add(itemInfo);
				loginfo(itemInfo.toString());
				// 递归遍历bom树
				recursion(bl);
			}
		}
	}

	private void loginfo(String info) {
		logger.info(info + "\r\n");
	}

	private Logger getLogger() {
		if (logger != null) {
			return logger;
		}
		Logger logger = Logger.getLogger("tang");
		logger.setLevel(Level.ALL); // 记录所有级别
		try {
			/* 设置用文件记录日志 */
			FileHandler fileHandler = new FileHandler("C:\\lidesen.txt"); // 文件目录如果不存在,它不会自动创建,会出异常
			fileHandler.setFormatter(new SimpleFormatter());
			logger.addHandler(fileHandler);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return logger;
	}
}

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-08-08 11:31:55  更:2021-08-08 11:32:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/3 2:26:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码