|
@@ -93,19 +93,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
} |
|
|
} |
|
|
// 如果是终态改变机器人状态 |
|
|
// 如果是终态改变机器人状态 |
|
|
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); |
|
|
List<String> finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); |
|
|
if(finishStatus.contains(jobQueryVO.getStatus()) ){ |
|
|
|
|
|
|
|
|
if (finishStatus.contains(jobQueryVO.getStatus())) { |
|
|
Rebot rebot = new Rebot(); |
|
|
Rebot rebot = new Rebot(); |
|
|
rebot.setStatus(RebotStatus.IDLE.getKey()); |
|
|
rebot.setStatus(RebotStatus.IDLE.getKey()); |
|
|
rebot.setUpdateBy("-1"); |
|
|
rebot.setUpdateBy("-1"); |
|
|
rebot.setUpdateTime(new Date()); |
|
|
rebot.setUpdateTime(new Date()); |
|
|
rebot.setStatus(RebotStatus.IDLE.getKey()); |
|
|
rebot.setStatus(RebotStatus.IDLE.getKey()); |
|
|
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName,jobQueryVO.getRobotClientName()).update(rebot); |
|
|
|
|
|
}else if(PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())){ |
|
|
|
|
|
|
|
|
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); |
|
|
|
|
|
} else if (PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())) { |
|
|
Rebot rebot = new Rebot(); |
|
|
Rebot rebot = new Rebot(); |
|
|
rebot.setStatus(RebotStatus.RUNNING.getKey()); |
|
|
rebot.setStatus(RebotStatus.RUNNING.getKey()); |
|
|
rebot.setUpdateBy("-1"); |
|
|
rebot.setUpdateBy("-1"); |
|
|
rebot.setUpdateTime(new Date()); |
|
|
rebot.setUpdateTime(new Date()); |
|
|
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName,jobQueryVO.getRobotClientName()).update(rebot); |
|
|
|
|
|
|
|
|
rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -119,32 +119,47 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
@Transactional |
|
|
@Transactional |
|
|
public boolean execPlan(ApplyStartBO applyStartBO) throws IllegalAccessException { |
|
|
public boolean execPlan(ApplyStartBO applyStartBO) throws IllegalAccessException { |
|
|
ListRebotBO listRebotBO = new ListRebotBO(); |
|
|
ListRebotBO listRebotBO = new ListRebotBO(); |
|
|
listRebotBO.setStatus("idle"); |
|
|
|
|
|
|
|
|
listRebotBO.setStatus(RebotStatus.IDLE.getKey()); |
|
|
listRebotBO.setPage(1); |
|
|
listRebotBO.setPage(1); |
|
|
listRebotBO.setSize(100); |
|
|
listRebotBO.setSize(100); |
|
|
// 只获取空闲的机器人 |
|
|
// 只获取空闲的机器人 |
|
|
List<ListRebotVO> listRebotVOS = YinDaoHttpUtils.listRebot(listRebotBO); |
|
|
|
|
|
if (listRebotVOS.isEmpty()) { |
|
|
|
|
|
|
|
|
List<ListRebotVO> listRebotVos = YinDaoHttpUtils.listRebot(listRebotBO); |
|
|
|
|
|
if (listRebotVos.isEmpty()) { |
|
|
log.error("暂无空闲机器人"); |
|
|
log.error("暂无空闲机器人"); |
|
|
// 刷新机器人数据 |
|
|
// 刷新机器人数据 |
|
|
// rebotService.syn(new Rebot()); |
|
|
// rebotService.syn(new Rebot()); |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
int i = 0; |
|
|
int i = 0; |
|
|
for (ListRebotVO listRebotVO : listRebotVOS) { |
|
|
|
|
|
|
|
|
for (ListRebotVO listRebotVO : listRebotVos) { |
|
|
ApplyPlan applyPlan = null; |
|
|
ApplyPlan applyPlan = null; |
|
|
|
|
|
// 查询所有待执行的任务 |
|
|
|
|
|
Map<Long, List<ApplyPlan>> applyPlanMap = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.ONE.getKey()).isNull(ApplyPlan::getTaskUuid) |
|
|
|
|
|
.orderByAsc(ApplyPlan::getPriority).list().stream().collect(Collectors.groupingBy(ApplyPlan::getDeptId)); |
|
|
|
|
|
if (null == applyStartBO && applyPlanMap.isEmpty()) { |
|
|
|
|
|
log.debug("没有等待执行的计划"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
// 获取每个部门优先级最高的计划 |
|
|
|
|
|
List<ApplyPlan> applyPlans = new ArrayList<>(); |
|
|
|
|
|
applyPlanMap.forEach((k, v) -> { |
|
|
|
|
|
v.sort((Comparator.comparingInt(ApplyPlan::getPriority))); |
|
|
|
|
|
applyPlans.add(v.get(0)); |
|
|
|
|
|
}); |
|
|
|
|
|
if (null == applyStartBO && applyPlans.isEmpty()) { |
|
|
|
|
|
log.debug("没有等待执行的计划"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
applyPlans.sort((Comparator.comparingInt(ApplyPlan::getPriority))); |
|
|
|
|
|
|
|
|
if (null == applyStartBO) { |
|
|
if (null == applyStartBO) { |
|
|
List<ApplyPlan> list = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.ONE.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getPriority).list(); |
|
|
|
|
|
if (list.isEmpty()) { |
|
|
|
|
|
log.debug("没有等待执行的计划"); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
applyPlan = list.get(0); |
|
|
|
|
|
|
|
|
applyPlan = applyPlans.get(0); |
|
|
applyStartBO = new ApplyStartBO(); |
|
|
applyStartBO = new ApplyStartBO(); |
|
|
applyStartBO.setRobotUuid(applyPlan.getAppId()); |
|
|
applyStartBO.setRobotUuid(applyPlan.getAppId()); |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
applyPlan = new ApplyPlan(); |
|
|
applyPlan = new ApplyPlan(); |
|
|
BeanUtils.copyBeanProp(applyPlan,applyStartBO); |
|
|
|
|
|
|
|
|
BeanUtils.copyBeanProp(applyPlan, applyStartBO); |
|
|
applyStartBO.setRobotUuid(applyStartBO.getRobotUuid()); |
|
|
applyStartBO.setRobotUuid(applyStartBO.getRobotUuid()); |
|
|
applyStartBO.setManualTime(applyStartBO.getManualTime()); |
|
|
applyStartBO.setManualTime(applyStartBO.getManualTime()); |
|
|
} |
|
|
} |
|
@@ -163,11 +178,13 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
updateApplyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); |
|
|
updateApplyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); |
|
|
updateApplyPlan.setRobotName(listRebotVO.getRobotClientName()); |
|
|
updateApplyPlan.setRobotName(listRebotVO.getRobotClientName()); |
|
|
updateApplyPlan.setManualTime(applyPlan.getManualTime()); |
|
|
updateApplyPlan.setManualTime(applyPlan.getManualTime()); |
|
|
if(this.saveOrUpdate(updateApplyPlan)){ |
|
|
|
|
|
|
|
|
updateApplyPlan.setDeptId(applyStartBO.getDeptId()); |
|
|
|
|
|
if (this.saveOrUpdate(updateApplyPlan)) { |
|
|
i++; |
|
|
i++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return i>0; |
|
|
|
|
|
|
|
|
return i > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@@ -187,6 +204,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
applyPlan.setAppType(apply.getAppType()); |
|
|
applyPlan.setAppType(apply.getAppType()); |
|
|
applyPlan.setAppTypeName(apply.getAppTypeName()); |
|
|
applyPlan.setAppTypeName(apply.getAppTypeName()); |
|
|
applyPlan.setManualTime(apply.getManualTime()); |
|
|
applyPlan.setManualTime(apply.getManualTime()); |
|
|
|
|
|
applyPlan.setDeptId(SecurityUtils.getDeptId()); |
|
|
|
|
|
|
|
|
// try { |
|
|
// try { |
|
|
// ApplyStartBO applyStartBO = new ApplyStartBO(); |
|
|
// ApplyStartBO applyStartBO = new ApplyStartBO(); |
|
@@ -209,7 +227,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
// } catch (Exception ex) { |
|
|
// } catch (Exception ex) { |
|
|
// log.error("分配机器人异常:" + ex.getMessage()); |
|
|
// log.error("分配机器人异常:" + ex.getMessage()); |
|
|
// } |
|
|
// } |
|
|
if(!insert.get()){ |
|
|
|
|
|
|
|
|
if (!insert.get()) { |
|
|
applyPlan.setTaskStatus(PlanRunStatus.AWAIT_CREATE.getKey()); |
|
|
applyPlan.setTaskStatus(PlanRunStatus.AWAIT_CREATE.getKey()); |
|
|
applyPlanList.add(applyPlan); |
|
|
applyPlanList.add(applyPlan); |
|
|
} |
|
|
} |
|
|