|
|
@@ -8,6 +8,7 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON; |
|
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
import com.ruoyi.business.domain.Apply; |
|
|
|
import com.ruoyi.business.domain.Rebot; |
|
|
|
import com.ruoyi.business.domain.ResourceLibrary; |
|
|
@@ -20,6 +21,7 @@ import com.ruoyi.business.service.IApplyService; |
|
|
|
import com.ruoyi.business.service.IRebotService; |
|
|
|
import com.ruoyi.business.service.IResourceLibraryService; |
|
|
|
import com.ruoyi.business.util.YinDaoHttpUtils; |
|
|
|
import com.ruoyi.business.yddoman.BaseDTO; |
|
|
|
import com.ruoyi.common.annotation.DataScope; |
|
|
|
import com.ruoyi.common.enums.ExcTypeStatus; |
|
|
|
import com.ruoyi.common.enums.PlanRunStatus; |
|
|
@@ -54,6 +56,16 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
@Autowired |
|
|
|
private IResourceLibraryService resourceLibraryService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 停止计划运行 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public boolean stopRun(JobQueryBO jobQueryBO) throws IllegalAccessException { |
|
|
|
BaseDTO baseDTO = YinDaoHttpUtils.appStop(jobQueryBO); |
|
|
|
return baseDTO.getSuccess(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 指定时间执行 |
|
|
@@ -91,16 +103,9 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
// 如果应用支持参数 |
|
|
|
if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { |
|
|
|
// 获取参数 |
|
|
|
List<ApplyStartBO.RobotParam> paramList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyStartBO.getRobotUuid()).list().stream() |
|
|
|
.map(item -> { |
|
|
|
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); |
|
|
|
robotParam.setName(item.getResourceName()); |
|
|
|
robotParam.setValue(item.getResourceValue()); |
|
|
|
robotParam.setType(item.getResourceType()); |
|
|
|
return robotParam; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if (paramList.isEmpty()) { |
|
|
|
if (StringUtils.isNotEmpty(e.getPlanParams())) { |
|
|
|
applyStartBO.setPlanParams(e.getPlanParams()); |
|
|
|
List<ApplyStartBO.RobotParam> paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); |
|
|
|
applyStartBO.setPlanParamsList(paramList); |
|
|
|
} |
|
|
|
} |
|
|
@@ -194,15 +199,9 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
// 如果应用支持参数 |
|
|
|
if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { |
|
|
|
// 获取参数 |
|
|
|
List<ApplyStartBO.RobotParam> paramList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyStartBO.getRobotUuid()).list().stream() |
|
|
|
.map(item -> { |
|
|
|
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); |
|
|
|
robotParam.setName(item.getResourceName()); |
|
|
|
robotParam.setValue(item.getResourceValue()); |
|
|
|
robotParam.setType(item.getResourceType()); |
|
|
|
return robotParam; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if (paramList.isEmpty()) { |
|
|
|
if (StringUtils.isNotEmpty(e.getPlanParams())) { |
|
|
|
applyStartBO.setPlanParams(e.getPlanParams()); |
|
|
|
List<ApplyStartBO.RobotParam> paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); |
|
|
|
applyStartBO.setPlanParamsList(paramList); |
|
|
|
} |
|
|
|
} |
|
|
@@ -249,6 +248,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取应用执行结果 |
|
|
|
* |
|
|
@@ -261,21 +261,17 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
// 不查询的状态 |
|
|
|
List<String> noStatus = new ArrayList<>(); |
|
|
|
noStatus.add(PlanRunStatus.FINISH.getKey()); |
|
|
|
noStatus.add(PlanRunStatus.WAITING.getKey()); |
|
|
|
noStatus.add(PlanRunStatus.STOPPED.getKey()); |
|
|
|
noStatus.add(PlanRunStatus.ERROR.getKey()); |
|
|
|
noStatus.add(PlanRunStatus.SKIPPED.getKey()); |
|
|
|
noStatus.add(PlanRunStatus.CANCEL.getKey()); |
|
|
|
// 查询任务运行状态非空非终态并且已经创建的任务 |
|
|
|
List<ApplyPlan> list = this.lambdaQuery().isNotNull(ApplyPlan::getTaskUuid).and(e -> { |
|
|
|
e.notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskStatus); |
|
|
|
}).orderByAsc(ApplyPlan::getPriority).list(); |
|
|
|
List<ApplyPlan> list = this.lambdaQuery().notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskStatus).orderByAsc(ApplyPlan::getPriority).list(); |
|
|
|
if (list.isEmpty()) { |
|
|
|
log.debug("没有需要更新状态的计划任务"); |
|
|
|
return; |
|
|
|
} |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
ApplyPlan applyPlan = list.get(i); |
|
|
|
for (ApplyPlan applyPlan : list) { |
|
|
|
JobQueryBO jobQueryBO = new JobQueryBO(); |
|
|
|
jobQueryBO.setJobUuid(applyPlan.getTaskUuid()); |
|
|
|
JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO); |
|
|
@@ -333,6 +329,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
/** |
|
|
|
* 执行计划(针对立即执行的计划) |
|
|
|
* |
|
|
|
* @param applyStartBO 该对象只有 应用id 优先级和人工用时 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
@@ -384,33 +381,23 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
applyPlan = applyPlans.get(0); |
|
|
|
applyStartBO = new ApplyStartBO(); |
|
|
|
applyStartBO.setRobotUuid(applyPlan.getAppId()); |
|
|
|
//high 高 middle 中 low 低 |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
} else { |
|
|
|
applyPlan = new ApplyPlan(); |
|
|
|
BeanUtils.copyBeanProp(applyPlan, applyStartBO); |
|
|
|
applyStartBO.setRobotUuid(applyStartBO.getRobotUuid()); |
|
|
|
applyStartBO.setManualTime(applyStartBO.getManualTime()); |
|
|
|
// 运行的应用上一步已给值,此处无需再给 |
|
|
|
} |
|
|
|
applyStartBO.setAccountName(listRebotVO.getRobotClientName()); |
|
|
|
//high 高 middle 中 low 低 |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
// 如果应用支持参数 |
|
|
|
if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { |
|
|
|
// 获取参数 |
|
|
|
List<ApplyStartBO.RobotParam> paramList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyStartBO.getRobotUuid()).list().stream() |
|
|
|
.map(e -> { |
|
|
|
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); |
|
|
|
robotParam.setName(e.getResourceName()); |
|
|
|
robotParam.setValue(e.getResourceValue()); |
|
|
|
robotParam.setType(e.getResourceType()); |
|
|
|
return robotParam; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if (paramList.isEmpty()) { |
|
|
|
if (StringUtils.isNotEmpty(applyPlan.getPlanParams())) { |
|
|
|
applyStartBO.setPlanParams(applyPlan.getPlanParams()); |
|
|
|
List<ApplyStartBO.RobotParam> paramList = JSON.parseArray(applyPlan.getPlanParams(), ApplyStartBO.RobotParam.class); |
|
|
|
applyStartBO.setPlanParamsList(paramList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); |
|
|
|
|
|
|
|
ApplyPlan updateApplyPlan = new ApplyPlan(); |
|
|
|
updateApplyPlan.setId(applyPlan.getId()); |
|
|
|
updateApplyPlan.setCreateBy("系统创建"); |
|
|
@@ -451,31 +438,34 @@ public class ApplyPlanServiceImpl extends ServiceImpl<ApplyPlanMapper, ApplyPlan |
|
|
|
applyPlan.setAppTypeName(apply.getAppTypeName()); |
|
|
|
applyPlan.setManualTime(apply.getManualTime()); |
|
|
|
if (null != apply.getSupportParam() && apply.getSupportParam() == 1) { |
|
|
|
applyPlan.setPlanParams(addApplyPlanBO.getPlanParams()); |
|
|
|
// 获取参数 每一次执行计划的参数都是独立的 |
|
|
|
List<ApplyStartBO.RobotParam> paramList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, apply.getAppId()).list().stream() |
|
|
|
.map(item -> { |
|
|
|
ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); |
|
|
|
robotParam.setName(item.getResourceName()); |
|
|
|
robotParam.setValue(item.getResourceValue()); |
|
|
|
robotParam.setType(item.getResourceType()); |
|
|
|
return robotParam; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if (paramList.isEmpty()) { |
|
|
|
// json集合转字符串 |
|
|
|
applyPlan.setPlanParams(JSONArray.toJSONString(paramList)); |
|
|
|
} |
|
|
|
} |
|
|
|
applyPlan.setDeptId(SecurityUtils.getDeptId()); |
|
|
|
|
|
|
|
// try { |
|
|
|
// ApplyStartBO applyStartBO = new ApplyStartBO(); |
|
|
|
// applyStartBO.setRobotUuid(applyPlan.getAppId()); |
|
|
|
// |
|
|
|
// ListRebotBO listRebotBO = new ListRebotBO(); |
|
|
|
// listRebotBO.setStatus("idle"); |
|
|
|
// listRebotBO.setPage(1); |
|
|
|
// listRebotBO.setSize(100); |
|
|
|
// // 只获取空闲的机器人 |
|
|
|
// List<ListRebotVO> listRebotVOS = YinDaoHttpUtils.listRebot(listRebotBO); |
|
|
|
// if (listRebotVOS.isEmpty()) { |
|
|
|
// log.debug("创建计划成功,但暂无空闲机器人"); |
|
|
|
// } |
|
|
|
// applyStartBO.setAccountName(listRebotVOS.get(0).getRobotClientName()); |
|
|
|
// //high 高 middle 中 low 低 |
|
|
|
// applyStartBO.setPriority("high"); |
|
|
|
// applyStartBO.setManualTime(applyPlan.getManualTime()); |
|
|
|
// insert.set(execPlan(applyStartBO)); |
|
|
|
// } catch (Exception ex) { |
|
|
|
// log.error("分配机器人异常:" + ex.getMessage()); |
|
|
|
// } |
|
|
|
try { |
|
|
|
// 只指定优先级和应用和人工用时 机器人等下一个阶段判读是否有空闲 |
|
|
|
ApplyStartBO applyStartBO = new ApplyStartBO(); |
|
|
|
applyStartBO.setRobotUuid(applyPlan.getAppId()); |
|
|
|
//high 高 middle 中 low 低 |
|
|
|
applyStartBO.setPriority("high"); |
|
|
|
applyStartBO.setManualTime(applyPlan.getManualTime()); |
|
|
|
applyStartBO.setPlanName(addApplyPlanBO.getPlanName()); |
|
|
|
insert.set(execPlan(applyStartBO)); |
|
|
|
} catch (Exception ex) { |
|
|
|
log.error("分配机器人异常:" + ex.getMessage()); |
|
|
|
} |
|
|
|
if (!insert.get()) { |
|
|
|
applyPlan.setTaskStatus(PlanRunStatus.AWAIT_CREATE.getKey()); |
|
|
|
applyPlanList.add(applyPlan); |
|
|
|