diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java index ee2b30f..c1ff591 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java @@ -147,6 +147,17 @@ public class ApplyPlan extends BaseEntity @ApiModelProperty(name="timeSaving",value = "节约时间") private String timeSaving; + /** 部门id */ + @Excel(name = "部门id") + @ApiModelProperty(name="deptId",value = "部门id") + private Long deptId; + + /** 部门名称 */ + @Excel(name = "部门名称") + @ApiModelProperty(name="deptName",value = "部门名称") + private String deptName; + + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 84aef2c..6165444 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -93,19 +93,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl 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.setStatus(RebotStatus.IDLE.getKey()); rebot.setUpdateBy("-1"); rebot.setUpdateTime(new Date()); 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.setStatus(RebotStatus.RUNNING.getKey()); rebot.setUpdateBy("-1"); 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 listRebotVOS = YinDaoHttpUtils.listRebot(listRebotBO); - if (listRebotVOS.isEmpty()) { + List listRebotVos = YinDaoHttpUtils.listRebot(listRebotBO); + if (listRebotVos.isEmpty()) { log.error("暂无空闲机器人"); // 刷新机器人数据 // rebotService.syn(new Rebot()); + return false; } int i = 0; - for (ListRebotVO listRebotVO : listRebotVOS) { + for (ListRebotVO listRebotVO : listRebotVos) { ApplyPlan applyPlan = null; + // 查询所有待执行的任务 + Map> 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 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) { - List 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.setRobotUuid(applyPlan.getAppId()); - }else{ + } else { applyPlan = new ApplyPlan(); - BeanUtils.copyBeanProp(applyPlan,applyStartBO); + BeanUtils.copyBeanProp(applyPlan, applyStartBO); applyStartBO.setRobotUuid(applyStartBO.getRobotUuid()); applyStartBO.setManualTime(applyStartBO.getManualTime()); } @@ -163,11 +178,13 @@ public class ApplyPlanServiceImpl extends ServiceImpl0; + return i > 0; } @Override @@ -187,6 +204,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl + + + + @@ -82,6 +86,8 @@ plan.end_time, plan.plan_time, plan.time_saving, + plan.dept_id, + plan.dept_name, plan.create_by, plan.create_time, plan.update_by, @@ -114,6 +120,8 @@ and end_time = #{endTime} and plan_time = #{planTime} and time_saving = #{timeSaving} + and dept_id = #{deptId} + and dept_name like concat(#{deptName}, '%') ${params.dataScope}