@Test
public void doTask() {
RuntimeService runtimeService = this.processEngine.getRuntimeService();
String processDefinitionKey = "myProcess";
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
System.out.println("流程启动成功:" + processInstance.getId());
/** 使用流程变量设置当日销售额,用来传递业务参数 */
int value = 0;// 应该是去查询数据库,进行汇总 ---耗时操做
int tryNum=0;//尝试汇总次数
while (true) {
tryNum++;
try {
value = this.hzxx();
break;
} catch (Exception e) {
e.printStackTrace();
if(tryNum==10) {
System.out.println("尝试10次汇总。所有失败,已终止汇总");
break;
}
}
}
runtimeService.setVariable(processInstance.getId(), "当前的销售额", value);
/** 向后执行一步,若是流程处于等待状态,使得流程继续执行 */
runtimeService.signal(processInstance.getId());
/** 从流程变量中获取汇总当日销售额的值 */
Integer saleMoney = (Integer) runtimeService//
.getVariable(processInstance.getId(), "当前的销售额");
System.out.println(saleMoney);
System.out.println("发送短信");
Boolean flag = false;
int num = 0;
do {
flag = send();
num++;
if (num == 10) {
System.out.println("尝试10次发送。所有失败,已终止发送");
break;
}
} while (!flag);
/** 向后执行一步,若是流程处于等待状态,使得流程继续执行 */
runtimeService.signal(processInstance.getId());
System.out.println("流程执行完成");
}
//汇总信息
public Integer hzxx() {
// 查询数据库
System.out.println("数据汇总中....");
try {
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("数据汇总完成");
return 10000;
}
//发送短信
private Boolean send() {
System.out.println("发送成功");
return true;
}