}
String expressionText=formalExpression.getBody();
if(expressionText==null){
throw new FixFlowException("超时表达式不能为空");
}
Date date=null;
String expressionTemp=null;//"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
List<Object> timeObjects=new ArrayList<Object>();
try {
Object dateObj=ExpressionMgmt.execute(expressionText, executionContext);
if(dateObj instanceof Date){
date=(Date)dateObj;
}
else{
if(dateObj instanceof List){
timeObjects=(List<Object>)dateObj;
}else{
expressionTemp=StringUtil.getString(dateObj);
}
}
} catch (Exception e) {
throw new FixFlowException("超时表达式计算失败!原因是: "+e.toString(),e);
}
TokenEntity tokenEntity=executionContext.getToken();
String processInstanceId=tokenEntity.getProcessInstance().getId();
/*VariableTransferEntity variableTransferEntity = new VariableTransferEntity();
Map<String, Object> transientVariableMap=tokenEntity.getProcessInstance().getContextInstance().getTransientVariableMap();
String guidString=GuidUtil.CreateGuid();
variableTransferEntity.addVariable(guidString, transientVariableMap);
if (processInstanceId != null && !processInstanceId.equals("")) {
VariableFlowTypeEntity variableFlowTypeEntity = new VariableFlowTypeEntity(VariableFlowType.PROCESSINSTANCE, processInstanceId);
variableTransferEntity.addVariableFlowType(variableFlowTypeEntity);
}
Context.getCommandContext().getVariableManager().saveVariable(variableTransferEntity);
*/
Scheduler scheduler=Context.getProcessEngineConfiguration().getScheduler();
Map<JobDetail, List<Trigger>> jobList=new HashMap<JobDetail, List<Trigger>>();
JobDetail job = QuartzUtil.createJobDetail(
TokenTimeOutJob.class, GuidUtil.CreateGuid()+"_"+tokenEntity.getId(), tokenEntity.getId()+"_"+processInstanceId+"_"+tokenEntity.getProcessInstance().getProcessDefinitionId());
job.getJobDataMap().put("tokenId", tokenEntity.getId());
//job.getJobDataMap().put("transientVariableId", guidString);
job.getJobDataMap().put("processInstanceId", processInstanceId);
job.getJobDataMap().put("nodeId", event.getId());
job.getJobDataMap().put("processKey", tokenEntity.getProcessInstance().getProcessDefinitionKey());
job.getJobDataMap().put("processId", tokenEntity.getProcessInstance().getProcessDefinitionId());
job.getJobDataMap().put("processName", tokenEntity.getProcessInstance().getProcessDefinition().getName());
job.getJobDataMap().put("bizKey", tokenEntity.getProcessInstance().getBizKey());
job.getJobDataMap().put("jobType", "fixTimeOutTask");
if(date==null){
if(expressionTemp!=null&&!expressionTemp.equals("")){
Trigger trigger = null;
trigger = QuartzUtil.createCronTrigger(
GuidUtil.CreateGuid(), "FixTimeOutTask_"+tokenEntity.getId(), expressionTemp);
List<Trigger> triggers=new ArrayList<Trigger>();
triggers.add(trigger);
jobList.put(job, triggers);
}else{
if(timeObjects.size()>0){
List<Trigger> triggers=new ArrayList<Trigger>();
for (Object object : timeObjects) {
if(object instanceof Date){
Trigger trigger = null;
trigger = (SimpleTrigger) QuartzUtil.createSimpleTrigger(
GuidUtil.CreateGuid(), "FixTimeOutTask_"+tokenEntity.getId(), StringUtil.getDate(object));
triggers.add(trigger);
}
if(object instanceof String){
Trigger trigger = null;
trigger = QuartzUtil.createCronTrigger(
GuidUtil.CreateGuid(), "FixTimeOutTask_"+tokenEntity.getId(), StringUtil.getString(object));
triggers.add(trigger);
}
}
jobList.put(job, triggers);
}else{
throw new FixFlowBizException("定时任务节点没有设置时间!");
}
}
}else{
Trigger trigger = null;
trigger = (SimpleTrigger) QuartzUtil.createSimpleTrigger(
GuidUtil.CreateGuid(), "FixTimeOutTask_"+tokenEntity.getId(), date);
List<Trigger> triggers=new ArrayList<Trigger>();
triggers.add(trigger);
jobList.put(job, triggers);
}
//QuartzUtil.createCronTrigger(jobName, groupName, cronExpression);
try {
scheduler.scheduleJobs(jobList, true);//.scheduleJob(job, trigger);
} catch (Exception e) {
throw new FixFlowException("超时任务启动记录失败!错误信息: "+e.toString(), e);
}
}