高级自定义 > 业务逻辑自定义 > Windchill ProjectLink 自定义 > 配置自动最后期限计算 > 为单独活动构造最后期限算法
  
为单独活动构造最后期限算法
执行以下步骤可为单独活动 (“叶活动”) 最后期限计算创建自定义算法。
事前准备:
您需要使用在设置最后期限模式中创建的活动子类型的内部名称。
查看注册的事件监听程序:最后期限和状况计算的注册事件监听程序
查看支持的 API:活动计算支持的 API
查看自定义处理程序指引:状况和最后期限计算的自定义处理程序指引
步骤 1:编写处理程序类
EPPDeadlineHandler 接口用于提供自定义计算算法:
EPPDeadlineHandler.java
calculateDeadline(<Collection of leaf activity objects>, event);
您可以扩展此接口并覆盖某些 API,以便使用自定义算法。例如,以下示例代码将根据活动的开始日期计算最后期限:

package com.ptc.projectmanagement.plan.EPPDeadlineHandler;
public class CustomDeadlineImplementation implements EPPDeadlineHandler {
@Override
public void calculateDeadline(ArrayList<PlanActivity> activitiesCollection, Object event)
throws WTException, WTPropertyVetoException {
try{
WTCollection leafAct = new WTArrayList();
WTCollection leafActivities = new WTArrayList(activitiesCollection);
leafActivities = CollectionsHelper.manager.refresh(leafActivities);
for (Object activity: leafActivities){
if(activity instanceof PlanActivity){
PlanActivity pActivity = (PlanActivity)activity;
Timestamp tmStart = pActivity.getStartDate();
pActivity.setDeadline(addDays(10, tmStart));
}
leafAct.add(pActivity);
}
PersistenceHelper.manager.save(leafAct);
//After saving the activities, the EPP_CUSTOM_DEADLINE_CHANGE event must be thrown
//so that the subsequent health status recalculations and notification emails are triggered.
PlanHelper.service.dispatchMultiEvent(ProjectManagementEvent.EPP_CUSTOM_DEADLINE_CHANGE,leafAct);
} catch(Exception ae){
ae.printStackTrace();
}
}
}
步骤 2:配置处理程序类
编写最后期限计算的自定义算法后,必须将其添加到 projectmanagement.service.properties.xconf 中。
1. 复制在设置最后期限模式中创建的活动子类型的内部名称。
2. 导航至以下位置:
${WT_HOME}\Windchill\codebase\com\ptc\projectmanagement\projectmanagement.service.properties.xconf
3. 编辑以下条目,以包含活动子类型的内部名称和处理程序类名称:
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "<internal type name>"
serviceClass="<fully qualified handler class name>"/>
</Service>
例如,给定上述示例处理程序类和内部名称 "org.rnd.Custom_Engineering_Activity":
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "org.rnd.Custom_Engineering_Activity"
serviceClass="com.ptc.projectmanagement.plan.CustomDeadlineImplementation"/>
</Service>
4. Windchill shell 运行以下命令:
xconfmanager -p
* 
PlanActivity 类型定义了以下预置处理程序。此处理程序不起作用:
<Service context="default" name="com.ptc.projectmanagement.plan.EPPDeadlineHandler">
<Option cardinality="singleton" requestor= "null"
selector = "com.ptc.projectmanagement.plan.PlanActivity"
serviceClass="com.ptc.projectmanagement.plan.PlanActivityDeadlineHandler"/>
</Service>