1.创建监听类
1.1创建类
1.在相应的模块创建一个Ibpl文件夹,并创建监听类,此处以会议预约例(此后所有代码都是基于会议-会议预约功能开发):
在com.landray.kmss.km.imeeting.lbpm下创建KmImeetingMeetingBookLbpmProcessFinishListener类,继承自IEventListener类,并重写handleEvent(EventExecutionContext execution, String parameter)方法,代码如下:
public void handleEvent(EventExecutionContext execution, String parameter) throws Exception {
}
1.2配置类
1.2.1注册bean
在WebContent\WEB-INF\KmssConfig\gh\planning\spring.xml下面注册创建好的bean。
<bean
id="KmImeetingMeetingBookLbpmProcessFinishListener"
class="com.landray.kmss.km.imeeting.lbpm.KmImeetingMeetingBookLbpmProcessFinishListener">
</bean>
1.2.2 配置监听
1.WebContent\WEB-INF\KmssConfig\gh\planning\plugin.xml下添加配置
2.参数:
point:配置的参数为流程事件。
model:需要监听的实体类。
unid:监听类的id,不可重复,一般可以用类名。
messageKey:监听事件显示名称,在ApplicationResources.properties内配置的,
此处(py.LiuChengJieShuShi=流程结束)。
eventTypes:lbpmProcessFinishEvent为流程结束事件。
listener:此为实现了IEventListener接口的实现类,此处为1.1新创建
KmImeetingMeetingBookLbpmProcessFinishListener。
<extension
point="com.landray.kmss.lbpm.engine.event"
model="com.landray.kmss.km.imeeting.model.KmImeetingBook">
<item
name="listener">
<param
name="unid"
value="kmImeetingMeetingBookLbpmProcessFinishListener"/>
<param
name="messageKey"
value="km-imeeting:py.LiuChengJieShuShi"/>
<param
name="eventTypes"
value="lbpmProcessFinishEvent"/>
<param
name="enforce"
value="true"/>
<param
name="listener"
value="kmImeetingMeetingBookLbpmProcessFinishListener"/>
</item>
</extension>
1.3 创建结束
1.当plugin.xml下配置model的对象流程结束之后,自动进入该实现类的handleEvent方法。
2.具体在流程结束之后需要执行的操作可以在实现类的handleEvent()方法中编写具体实现。
3.此为强制监听,无论是否配置,都会执行监听,区别于非强制监听。
2.后台配置
2.1新建配置对象
在com.landray.kmss.km.imeeting.model下新增BaseConfig类,继承于BaseAppConfig。
package com.landray.kmss.km.imeeting.model;
import com.landray.kmss.sys.appconfig.model.BaseAppConfig;
/**
* 基本配置信息
*/
public class BaseConfig extends BaseAppConfig {
public BaseConfig() throws Exception {
super();
}
public String getJSPUrl() {
return "/km/imeeting/common/base_config.jsp";
}
@Override
public String getValue(String name) {
return super.getValue(name);
}
/**
* 获取实例
*
* @return
*/
public static BaseConfig get() {
try {
return new BaseConfig();
} catch (Exception e) {
return null;
}
}
/**
* 获取配置项
*
* @param key
* 表单name值
* @return
*/
public static String get(String key) {
try {
return get().getValue(key);
} catch (Exception e) {
return "";
}
}
}
2.2 新建jsp页面
此处为后台配置的显示页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/resource/jsp/edit_top.jsp"%>
<html:form action="/sys/appconfig/sys_appconfig/sysAppConfig.do">
<div id="optBarDiv">
<input type=button value="<bean:message key="button.update"/>"
onclick="Com_Submit(document.sysAppConfigForm, 'update');">
</div>
<p class="txttitle">
基础设置
</p>
<center>
<table class="tb_normal" width=95% style="margin-bottom: 120px;">
<tr>
<td class="td_normal_title" width="15%">
会议预约通知人员
</td>
<td>
<xform:address propertyId="value(base.kmImeetingBook.inform.fdPersonIds)" propertyName="value(base.kmImeetingBook.inform.fdPersonNames)" mulSelect="true" orgType="ORG_TYPE_PERSON" showStatus="edit" style="width:85%" />
</td>
</tr>
</table>
</center>
</html:form>
<script>
$KMSSValidation();
</script>
<%@ include file="/resource/jsp/edit_down.jsp"%>
2.3 添加配置页面显示
在\WebContent\km\imeeting\tree.jsp中添加如下配置:
<%-- 会议室预约 --%>
n10 = n6.AppendURLChild("<bean:message key="table.kmImeetingBook" bundle="km-imeeting"/>","<c:url
value="/km/imeeting/km_imeeting_book/index.jsp"/>");
/*基础设置*/
n10 = n6.AppendURLChild (
'会议预约通知人员',
'<c:url
value="/sys/appconfig/sys_appconfig/sysAppConfig.do?method=edit&modelName=com.landray.kmss.km.imeeting.model.BaseConfig"/>')
2.4 配置
后台==》会议管理后台==》会议预约==》会议预约通知人员
2.5配置结束
该配置类可以在任意模块下,快速新建一个后台配置类,一般用于后续添加配置项操作。
3.发送通知
此处为1中创建的监听类,在流程结束后,向2中配置的人员发送待阅通知。
3.1获取通知发送类
ISysNotifyMainCoreService类的send(ISysNotifyModel var1, NotifyContext var2, HashMap var3) 方法实现了具体的发送通知功能。
private ISysNotifyMainCoreService sysNotifyMainCoreService;
public ISysNotifyMainCoreService getSysNotifyMainCoreService() {
if (sysNotifyMainCoreService == null) {
sysNotifyMainCoreService = (ISysNotifyMainCoreService) SpringBeanUtil.getBean("sysNotifyMainCoreService");
}
3.2 拼接发送对象
此处为将2中配置的全部人员添加到数组targets0中,并设置为接收人。
BaseConfig baseConfig = new BaseConfig();
String value = baseConfig.getValue("base.costApplyHysq.inform.fdPersonIds");
String[] personIds = value.split(";");
List<SysOrgElement> targets0 = new ArrayList<SysOrgElement>();
ISysOrgPersonService sysOrgPersonService=(ISysOrgPersonService) SpringBeanUtil.getBean("sysOrgPersonService");
List byPrimaryKeys = sysOrgPersonService.findByPrimaryKeys(personIds);
targets0.addAll(byPrimaryKeys);
notifyContext0.setNotifyTarget(targets0);
1.发送类型设置:1代办 2待阅
2.发送标题:显示内容
3.key:必须保证key的唯一,一定不要与其他通知事件重复。
4.链接:设置点击通知之后的跳转地址
//1
notifyContext0.setFlag("2");
//2
notifyContext0.setSubject(ResourceUtil.getString("cost.apply.hysq.finish.notify.subject", "cost-apply"));
notifyContext0.setNotifyType("todo");
//3
notifyContext0.setKey(ResourceUtil.getString("cost.apply.hysq.finish.notify.key", "cost-apply"));
//4
notifyContext0.setLink("/cost/apply/cost_apply_hysq/costApplyHysq.do?method=view&fdId=" + costApplyHysq.getFdId());
3.3发送
拼接好数据后,调用ISysNotifyMainCoreService的send方法即可,发送内容,发送人,点击跳转链接在3.2已配置完成。
getSysNotifyMainCoreService().send(costApplyHysq, notifyContext0, null);
3.4 发送完成
4.结束
上述1,2,3功能都可单独使用。
例如:
(1)可以A文档完成后修改B文档状态可以在1中直接修改;
(2)需要新增配置选项显示在前端做选择,可以直接用2实现;(3)提交文档发送通知,可以在具体方法的save中实现发送通知功能即可;