/**
* 更新明细状态
*/
public void updateDetailStatus(String detailId,boolean success,String errMsg){
PlanDetail detail = getDetailWithLock(detailId);
if( detail == null )
throw new ApplicationException("执行计划明细["+detailId+"]对应数据不存在!");
PlanDetail.Status oldStatus = detail.getStatus();
if( PlanDetail.Status.WAITING_FOR_REPLY.equals(detail.getStatus())
|| PlanDetail.Status.NEW.equals(detail.getStatus())
|| PlanDetail.Status.FAILURE.equals(detail.getStatus())
|| PlanDetail.Status.EXCEPTION.equals(detail.getStatus()) ){
detail.setStatus(success?PlanDetail.Status.SUCCESS:PlanDetail.Status.FAILURE);
detail.setFinishTime( Calendar.getInstance() );
if( StringUtils.isEmpty(errMsg))
detail.setDescription("回调结果["+(success?"成功":"失败")+"]");
else
detail.setDescription( TextFormater.format(errMsg,197,true) );
this.planDetailDao.update(detail);
log.info("执行计划明细["+detailId+"]状态["
+oldStatus+"]更新为["+detail.getStatus()+"]!");
//TODO 并发可能导致 计划任务状态 不能成功更新
/*
if( success ){
String planId = detail.getPlan().getId();
int count = getUnsuccessfulCount( planId,detail.getId());
if( count == 0 ){
updateFinishTime( planId,Calendar.getInstance());
log.info("执行计划明细[{}]执行完成,整个任务完成!",detail.getId());
}
}
*/
//TODO 可能导致并发问题
//执行依赖任务
/*
List<PlanDetail> replyOnList = planDetailDao.listRelyOnUnsuccessful(detailId);
if( replyOnList == null || replyOnList.isEmpty() )
return;
//TODO 线程池处理
for( PlanDetail item:replyOnList ){
if( item.getPlan()==null || item.getPlan().getType() == null ){
log.warn("上级任务执行[{}]依赖任务[{}]无法调用执行,类型为空!",detailId,item.getId());
continue;
}else if( success ){
log.info("回调任务[{}]执行成功,执行依赖任务[{}]。",detailId,item.getId());
jobQueueManager.jobInQueue(item.getPlan().getType().getId(),item.getId(),1);
}else{
item.setStatus(Status.FAILURE);
item.setDescription("依赖任务["+detailId+"]执行返回失败!");
planDetailDao.update(item);
}
}*/
}else{
log.warn("执行计划明细["+detailId
+"]状态已改变为["+detail.getStatus()+"]不能进行更新!");
}
}