Windchill 建模之模型对象可以挂附件

最近在做一个需求的时候,行数据里面需要保存用户上传的附件,所以和小伙伴开发的时候决定在模型上完成这个操作。

实现方式:
模型继承ContentHolder

如下为模型类的定义:

package ext.cts.model;

import com.ptc.windchill.annotations.metadata.ColumnProperties;
import com.ptc.windchill.annotations.metadata.GenAsPersistable;
import com.ptc.windchill.annotations.metadata.GeneratedProperty;
import com.ptc.windchill.annotations.metadata.PropertyConstraints;
import com.ptc.windchill.annotations.metadata.Serialization;

import wt.content.ContentHolder;
import wt.fc.WTObject;
import wt.util.WTException;

/**
 * CTS发布新建CU BOM请求单,行数据
 * @author gang.yi
 *
 */
@GenAsPersistable(superClass = WTObject.class, interfaces = {ContentHolder.class}, serializable = Serialization.EXTERNALIZABLE_BASIC, properties = {
		@GeneratedProperty(name = "linenum", type = String.class, javaDoc = "行号",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "ctsNumber", type = String.class, javaDoc = "CTS请求编码",
			constraints = @com.ptc.windchill.annotations.metadata.PropertyConstraints(upperLimit = 30, required = true) ,columnProperties = @ColumnProperties(index = true)),
		@GeneratedProperty(name = "productName", type = String.class, javaDoc = "项目名",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "cuReference", type = String.class, javaDoc = "CU Ref编码",constraints = @PropertyConstraints(upperLimit = 100)
			,columnProperties = @ColumnProperties(index = true)),
		@GeneratedProperty(name = "color", type = String.class, javaDoc = "颜色",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "brand", type = String.class, javaDoc = "品牌",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "modelName", type = String.class, javaDoc = "型号",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "simLock", type = String.class, javaDoc = "SIM Lock",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "remark", type = String.class, javaDoc = "备注",constraints = @PropertyConstraints(upperLimit = 1000)),
		@GeneratedProperty(name = "fileNames", type = String.class, javaDoc = "附件文档名称,可以有多个",constraints = @PropertyConstraints(upperLimit = 1000)),
		@GeneratedProperty(name = "fileNumbers", type = String.class, javaDoc = "文档编码(提交流程后才会有),可以有多个",constraints = @PropertyConstraints(upperLimit = 600)),
		@GeneratedProperty(name = "requestNo", type = String.class, javaDoc = "sts启动的请求流程编码(PBO编码)",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "state", type = String.class, javaDoc = "状态, Draft、 OnGoing、Closed",constraints = @PropertyConstraints(upperLimit = 100)),
		@GeneratedProperty(name = "changeNumber", type = String.class, javaDoc = "PSD手动起的CU流程编码",constraints = @PropertyConstraints(upperLimit = 200)),
		@GeneratedProperty(name = "requestWFID", type = String.class, javaDoc = "CTS请求流程ida2a2",constraints = @PropertyConstraints(upperLimit = 100)
			,columnProperties = @ColumnProperties(index = true))
})
public class ReleaseRequestDetail extends _ReleaseRequestDetail{
	static final long serialVersionUID = 1;

	public static ReleaseRequestDetail newInstance()throws WTException {
		final ReleaseRequestDetail instance = new ReleaseRequestDetail();
		instance.initialize();
		return instance;
	}

	protected void initialize() throws WTException {
		
	}
}

下面是save对象的时候保存附件的代码

private static void addReleaseRequestDetailApplicationData(ReleaseRequestDetail detailInfo, String fileNames)
			throws WTException, WTPropertyVetoException, PropertyVetoException, IOException, FileNotFoundException {
		String[] files = fileNames.split(";");
		if (files.length > 0) {
			for (int i = 0; i < files.length; i++) {
				ApplicationData applicationdata = ApplicationData.newApplicationData(detailInfo);
				applicationdata.setRole(ContentRoleType.SECONDARY);
				applicationdata = ContentServerHelper.service.updateContent(detailInfo, applicationdata, files[i]);
			}
		}
	}

下面代码是获取附件的代码:

ReleaseRequestDetail createDetail = this.createDetail;
QueryResult qr = ContentHelper.service.getContentsByRole(createDetail, ContentRoleType.SECONDARY);
if (qr.hasMoreElements()) {
	ApplicationData data = (ApplicationData) qr.nextElement();
}

模型配置文件增加配置:

descendentRegistry.properties文件新增
wt.fc.WTObject=ext.cts.model.CUBOMRequestBasicInfo
wt.fc.WTObject=ext.cts.model.ChangeRequestDetail
wt.fc.WTObject=ext.cts.model.ReleaseRequestDetail
wt.fc.WTObject=ext.cts.model.RequestChangeRecord
**wt.content.ContentHolder=ext.cts.model.ChangeRequestDetail**
**wt.content.ContentHolder=ext.cts.model.ReleaseRequestDetail**

modelRegistry.properties文件中新增
ext.cts.model=CUBOMRequestBasicInfo
ext.cts.model=ChangeRequestDetail
ext.cts.model=ReleaseRequestDetail
ext.cts.model=RequestChangeRecord

其他步骤和建模的常规套路一样

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章