1.定义一个添加消息的方法
//消息通知方法
public static void sendWorkFlowMessage(Context ctx,String Receiver,String Body,String title,String sender) throws EASBizException, BOSException{
BMCMessageInfo messageInfo = new BMCMessageInfo();
messageInfo.setTitle(title);//表题
messageInfo.setBody(Body);//内容
messageInfo.setReceiver(Receiver);// TODO设置接收者,后面那参数是用户ID,多个ID可用分号";"分割
messageInfo.setType(MsgType.ONLINE); // 即时消息
messageInfo.setBizType(MsgBizType.ONLINE); // 消息类型 - 即时消息
messageInfo.setSender(sender); //发送人
messageInfo.setPriority(MsgPriority.HIGH);// 消息级别
messageInfo.setSendTime(new Timestamp(new Date().getTime()));//接收时间
messageInfo.setOrgType(OrgType.NONE);//设置组织类型
messageInfo.setOrgID("11111111-1111-1111-1111-111111111111CCE7AED4");//设置管理单元
BMCMessageFactory.getLocalInstance(ctx).save(messageInfo);//发送消息
}
2.调用这个方法
//一级部门新增成功调用的通知消息方法
public void DepartmentNotice(Context ctx,FullOrgUnitInfo info){
String title = "";
String body = "";
boolean flag = info.getNumber() == null ? false : true;
if (flag) {
title = "一级部门通知消息";
body = title+",编码为:"+info.getNumber()+",名称为:"+info.getName();
}
Set<String> set = new HashSet<String>();
UserInfo currentUser = ContextUtil.getCurrentUserInfo(ctx);
String sender = currentUser.getName();
String receiver = "";
try {
StringBuffer sql = new StringBuffer();
sql.append("/*dialect*/select tu.FID fd from T_PM_User tu ");
sql.append("left join T_BD_Person tp ");
sql.append("on tp.FID = tu.FPERSONID ");
sql.append("where tp.CFMessage = '1' ");
IRowSet rows = DbUtil.executeQuery(ctx, sql.toString());
if (rows != null && rows.size() > 0) {
while (rows.next()) {
receiver = rows.getString("fd");//用户的ID
set.add(receiver);
}
}
if (!("".equals(title) && "".equals(body))&& !((title == null )&&(body == null))) {
//调用发送消息方法
if (set.size() > 0) {
Iterator<String> it2 = set.iterator();
while (it2.hasNext()) {
sendWorkFlowMessage(ctx,it2.next(),body,title,sender);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
发送即时消息,其实就是对消息数据进行新增的操作