/** * 采用活动定义、流程实例以及活动参与者ID号构造 * * @param define 活动定义 * @param process 流程实例 * @param person 活动参与者 */ public ActivityInstance( ActivityDef define, ProcessInstance process, String actorExpression, String sender, String sendid, ActivityInstance foreActivityIns) throws Exception { this.define = define; this.defid = define.getID(); this.process = process; this.actorexpression = actorExpression; this.processName = this.process.getName(); this.defname = this.define.getName(); // 活动发送人,发送时间 this.setSender(sender); this.setSenderId(sendid); this.setSendTime(new Date()); this.foreActivityInstance = foreActivityIns; // 设置活动状态 state = "开始活动"; // 添加到流程中 process.add(this); }
/** 结束活动 */ public synchronized void finish( Session session, String personExpression, String username, String userid) throws Exception { // 解析传递过来的对象属性 JSONArray array = new JSONArray(personExpression); JSONObject firstObj = array.getJSONObject(0); final String data = firstObj.getString("data"); JSONObject dataObj = new JSONObject(data); // 把前台传过来的,活动对应的人员,转换成json串 state = "结束"; // 设置完成人,完成时间 this.setPerson(username); this.setUserid(userid); this.setFinishTime(new Date()); // 根据每个转移创建任务和活动 ProcessDef procDef = ProcessDefManager.getInstance().getProcessDef(processName); ActivityDef actDef = procDef.getActivity(defid); for (DiversionDef divDef : actDef.getSplits()) { ActivityDef tailDef = divDef.getTail(); // 给流程中的变量赋值 this.process.putVar(dataObj); // 如果不满足表达式条件,继续下一个 String expression = divDef.getExpression(); if (expression != null && !expression.equals("") && !this.process.getExpressionValue(expression)) { continue; } // 根据人员表达式,产生人员对照表 String exp = tailDef.getPersonExpression(); if (dataObj.has(tailDef.getName())) { String pExp = dataObj.getString(tailDef.getName()); exp = pExp; } PersonService.Run(exp, session); ActivityInstance actIns = new ActivityInstance(tailDef, process, exp, username, userid, this); session.save(actIns); } session.update(this); }