JBMP流程引擎
流程设计
最简单的一个流程配置包括下面几部分:
- 开始节点、人工处理环节(包括参与人、动作)、结束节点;
- 参与人:可配置具体用户、用户组、或者表达式,动作可以配置执行的后置事件。
- 参与人表达式配置。
- 动作配置执行的后置事件。
流程发起
- 发起的主要方法:bwService.startProcess(userid, "RFP_TRADETRANSACTIONS_APPROVE", sendapprovelist, map);
- userid:发起用户
- RFP_TRADETRANSACTIONS_APPROVE:流程设计阶段定义的流程KEY
- sendapprovelist:与流程相关的业务数据,主要是单据的主键,用于流程审批时加载自定义表单查询数据使用
- map:传入流程中的变量,可以用于流程条件
public void sendApprove(CommonTransfer<TransAccountDetail> context) throws Exception {
String[] urids = ((String)context.getProperties().get("ids")).split(",");
String userid = (String)context.getProperties().get("userid");
IDBSession session = DBSessionAdapter.getSession();
TransAccountDetailDao transAccountDetailDao=new TransAccountDetailDao(session);
TradeAccountDao tradeAccountDao=new TradeAccountDao(session);
for (String urid : urids) {
if (FString.isNullOrEmpty(urid)) {
throw new Exception("数据异常,urid字段值非法(为空)!");
}
TransAccountDetail transAccountDetail = transAccountDetailDao.getByUrid(urid);
if (transAccountDetail == null) {
throw new Exception("数据异常,无法通过urid找到相应的交易明细");
}
if(transAccountDetailDao.existApproving(transAccountDetail)){
throw new ServiceException(ErrorCodeConstants.TAM00013);
}
TradeAccount tradeAccount = tradeAccountDao.getByUrid(transAccountDetail.getTradeaccountsid());
IBusinessWorkflowService bwService = (IBusinessWorkflowService) Globals.getBean("bizWorkflowService");
List<String> sendapprovelist = new ArrayList<String>();
Map<String, Object> map = new HashMap<String, Object>();
sendapprovelist.add(transAccountDetail.getUrid());
map.put("$_ORG_ID", tradeAccount.getOrgid());
bwService.startProcess(userid, "RFP_TRADETRANSACTIONS_APPROVE", sendapprovelist, map);
//更新审批状态为审批中
transAccountDetail.setRowversion(transAccountDetail.getRowversion()+1);
transAccountDetail.setApprovestate(ENApproveState.APPROVING.getValue());
transAccountDetailDao.updateWithRowversion(transAccountDetail);
}
}
流程中查找审批用户表达式
- 新建一个普通类,配置spring Bean,UserQueryDao就是bean的名称
public List<User> getUserByOrgAndRole(String orgid, String Roles) {
List<User> list = new ArrayList<User>();
StringBuilder SQL = new StringBuilder();
SQL.append("select e.user_code from tsys_user e where e.org_id ='"+orgid+"'" and e.role_code in ("+Roles+") and e.right_flag = 1");
List<String> result=ht.getSessionFactory().getCurrentSession().createSQLQuery(SQL.toString()).list();
for(String userId:result){
UserImpl uimpl=new UserImpl();
uimpl.setId(userId);
list.add(uimpl);
}
return list;
}