Browse Source

123

pull/4/head
lcr 3 months ago
parent
commit
7ad00a6d86
3 changed files with 56 additions and 19 deletions
  1. +11
    -0
      ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java
  2. +37
    -19
      ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java
  3. +8
    -0
      ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml

+ 11
- 0
ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java View File

@@ -147,6 +147,17 @@ public class ApplyPlan extends BaseEntity
@ApiModelProperty(name="timeSaving",value = "节约时间") @ApiModelProperty(name="timeSaving",value = "节约时间")
private String timeSaving; 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 @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)


+ 37
- 19
ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java View File

@@ -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);
} }


+ 8
- 0
ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml View File

@@ -45,6 +45,10 @@
<result property="planTime" column="plan_time" /> <result property="planTime" column="plan_time" />
<!-- 节约时间 --> <!-- 节约时间 -->
<result property="timeSaving" column="time_saving" /> <result property="timeSaving" column="time_saving" />
<!-- 部门id -->
<result property="deptId" column="dept_id" />
<!-- 部门名称 -->
<result property="deptName" column="dept_name" />
<!-- 创建者 --> <!-- 创建者 -->
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<!-- 创建时间 --> <!-- 创建时间 -->
@@ -82,6 +86,8 @@
plan.end_time,<!-- 任务结束运行的时间 --> plan.end_time,<!-- 任务结束运行的时间 -->
plan.plan_time,<!-- 实际耗时 --> plan.plan_time,<!-- 实际耗时 -->
plan.time_saving,<!-- 节约时间 --> plan.time_saving,<!-- 节约时间 -->
plan.dept_id,<!-- 部门id -->
plan.dept_name,<!-- 部门名称 -->
plan.create_by,<!-- 创建者 --> plan.create_by,<!-- 创建者 -->
plan.create_time,<!-- 创建时间 --> plan.create_time,<!-- 创建时间 -->
plan.update_by,<!-- 更新者 --> plan.update_by,<!-- 更新者 -->
@@ -114,6 +120,8 @@
<if test="endTime != null "> and end_time = #{endTime}</if> <if test="endTime != null "> and end_time = #{endTime}</if>
<if test="planTime != null and planTime != ''"> and plan_time = #{planTime}</if> <if test="planTime != null and planTime != ''"> and plan_time = #{planTime}</if>
<if test="timeSaving != null and timeSaving != ''"> and time_saving = #{timeSaving}</if> <if test="timeSaving != null and timeSaving != ''"> and time_saving = #{timeSaving}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat(#{deptName}, '%')</if>
</where> </where>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope} ${params.dataScope}


Loading…
Cancel
Save