diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 191d629..a7083fe 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -3,13 +3,13 @@ spring: # redis 配置 redis: # 地址 - host: 192.168.10.136 + host: 192.168.10.214 # 端口,默认为6379 port: 6379 # 数据库索引 - database: 13 + database: 0 # 密码 - password: wjcy@123456 + password: Aa@123456 # 连接超时时间 timeout: 10s lettuce: @@ -28,9 +28,9 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://192.168.10.136:3306/wjcy_new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: wjcy@123456 + url: jdbc:mysql://192.168.10.214:3306/wjcy_new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: wjcy_new + password: PHPKL3p3ME2pGT4j # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 6e78cb6..7340ef2 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -65,28 +65,6 @@ spring: restart: # 热部署开关 enabled: true - # redis 配置 - redis: - # 地址 - host: 192.168.10.136 - # 端口,默认为6379 - port: 6379 - # 数据库索引 - database: 13 - # 密码 - password: wjcy@123456 - # 连接超时时间 - timeout: 10s - lettuce: - pool: - # 连接池中的最小空闲连接 - min-idle: 0 - # 连接池中的最大空闲连接 - max-idle: 8 - # 连接池的最大数据库连接数 - max-active: 8 - # #连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms # token配置 token: diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java index bf9815c..a3a28f9 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java @@ -97,12 +97,11 @@ public class ApplyController extends BaseController { List planList = applyPlanService.lambdaQuery().isNotNull(ApplyPlan::getManualTime) .and(e -> e.in(ApplyPlan::getExcType, "0", "1") .eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).or().eq(ApplyPlan::getExcType, "2")) - .list(); // 只过滤执行计划的id List planIdList = planList.stream().filter(e -> "2".equals(e.getExcType())).map(ApplyPlan::getId).collect(Collectors.toList()); // 获取所有 设置了时间并且是完成状态的计划记录 - LambdaQueryChainWrapper qw = applyPlanLogService.lambdaQuery(); + LambdaQueryChainWrapper qw = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getStatus,"0"); List planLogList = null; if (planIdList.isEmpty()) { planLogList = new ArrayList<>(); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java index fd3c9bc..f9cc0f7 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java @@ -56,7 +56,7 @@ public class ApplyRebotController extends BaseController { @ApiOperation(value = "查询所有应用和机器人绑定列表", httpMethod = "GET", response = Apply.class) @GetMapping("/listAll") public AjaxResult listAll(ApplyRebot applyRebot) { - List applyRebotList = applyRebotService.list(applyRebot); + List applyRebotList = applyRebotService.list(applyRebot).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); return AjaxResult.success(applyRebotList); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java index 7a8c2c8..7f4fb58 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java @@ -1,6 +1,7 @@ package com.ruoyi.business.domain; import java.util.Date; + import com.fasterxml.jackson.annotation.JsonFormat; import com.baomidou.mybatisplus.annotation.*; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -28,47 +29,60 @@ import com.ruoyi.common.core.domain.BaseEntity; @Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor -@ApiModel(value="ApplyPlanLog",description = "应用执行结果记录管理") +@ApiModel(value = "ApplyPlanLog", description = "应用执行结果记录管理") @TableName(value = "ct_apply_plan_log") -public class ApplyPlanLog extends BaseEntity -{ +public class ApplyPlanLog extends BaseEntity { @TableField(exist = false) private static final long serialVersionUID = 1L; - - /** 计划id */ + /** + * 计划id + */ @Excel(name = "计划id") - @ApiModelProperty(name="planId",value = "计划id") + @ApiModelProperty(name = "planId", value = "计划id") private String planId; - /** 所属应用id */ + /** + * 所属应用id + */ @Excel(name = "所属应用id") - @ApiModelProperty(name="appId",value = "所属应用id") + @ApiModelProperty(name = "appId", value = "所属应用id") private String appId; - /** 计划job_uuid */ + /** + * 计划job_uuid + */ @Excel(name = "计划job_uuid") - @ApiModelProperty(name="jobUuid",value = "计划job_uuid") + @ApiModelProperty(name = "jobUuid", value = "计划job_uuid") private String jobUuid; - /** 输出内容 */ + /** + * 输出内容 + */ @Excel(name = "输出内容") - @ApiModelProperty(name="outParam",value = "输出内容") + @ApiModelProperty(name = "outParam", value = "输出内容") private String outParam; + /** + * 执行结果(0成功 1失败) + */ + @Excel(name = "执行结果(0成功 1失败)") + @ApiModelProperty(name = "status", value = "执行结果(0成功 1失败)") + private String status; + @Override public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .append("deleted", getDeleted()) - .toString(); + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("deleted", getDeleted()) + .toString(); } } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java index ed79165..307964e 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java @@ -15,5 +15,10 @@ public class JobQueryBO { * 应用运行的uuid, 由job/start接口返回 */ private String jobUuid; + + /** + * 是否应用新参数 + */ + private Boolean newData; } 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 6c9a7a4..9ba7f84 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 @@ -98,6 +98,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl 0; + // 状态异常重新创建任务 删除原任务,如果是周期则有任务日志,改变原日志关联id,重新创建的任务绑定新的参数 + // 已停止状态重新运行,获取的是旧参数 + ApplyPlan plan = applyPlanService.lambdaQuery().eq(ApplyPlan::getTaskUuid, jobQueryBO.getJobUuid()).one(); + // 获取应用信息 + Apply apply = applyService.lambdaQuery().eq(Apply::getAppId, plan.getAppId()).one(); + + try { + // 周期,将日志绑定到新计划 + if ("2".equals(plan.getExcType())) { + ApplyPlan newApplyPlan = new ApplyPlan(); + createApplyPlan(jobQueryBO, plan, apply, newApplyPlan); + // 换绑日志 + ApplyPlanLog applyPlanLog = new ApplyPlanLog(); + applyPlanLog.setPlanId(newApplyPlan.getId()); + applyPlanLogService.lambdaUpdate().eq(ApplyPlanLog::getPlanId, plan.getId()).update(applyPlanLog); + } else { + createApplyPlan(jobQueryBO, plan, apply, new ApplyPlan()); + } + } catch (Exception ex) { + ex.printStackTrace(); + throw ex; + } + return true; + } + + /** + * 创建一个计划 + * + * @return + */ + private boolean createApplyPlan(JobQueryBO jobQueryBO, ApplyPlan plan, Apply apply, ApplyPlan newApplyPlan) { + // 创建一个新计划 + BeanUtils.copyBeanProp(newApplyPlan, plan); + newApplyPlan.setId(null); + newApplyPlan.setTaskStatus(PlanRunStatus.AWAIT_CREATE.getKey()); + newApplyPlan.setNextExecTime(newApplyPlan.getLastExecTime()); + if (jobQueryBO.getNewData()) { + if (null != apply.getSupportParam() && apply.getSupportParam() == 1) { + newApplyPlan.setSupportParam(apply.getSupportParam()); + // 获取参数列表 + List resourceLibraryList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, plan.getAppId()).list(); + // 获取参数 每一次执行计划的参数都是独立的 + List paramList = resourceLibraryList.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()) { + throw new ServiceException("该应用需要参数,没有检测到参数!"); + } else { + // json集合转字符串 + newApplyPlan.setPlanParams(JSONArray.toJSONString(paramList)); + } + } } else { - return false; + if (null != apply.getSupportParam() && apply.getSupportParam() == 1) { + newApplyPlan.setSupportParam(apply.getSupportParam()); + newApplyPlan.setPlanParams(plan.getPlanParams()); + } } + // 先删除 在新增 + applyPlanService.removeById(plan.getId()); + return applyPlanService.save(newApplyPlan); } /** @@ -239,56 +307,54 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } - List ids = new ArrayList<>(); - runRebotList.forEach(rebot -> { - applyPlanList.forEach(e -> { - log.debug("指定时间执行 执行时间:" + e.getExcTime()); - if (ids.contains(e.getId())) { - return; - } - if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { - ApplyStartBO applyStartBO = new ApplyStartBO(); - applyStartBO.setRobotUuid(e.getAppId()); - applyStartBO.setAccountName(rebot.getRobotClientName()); - applyStartBO.setManualTime(e.getManualTime()); - //high 高 middle 中 low 低 - applyStartBO.setPriority("high"); - // 如果应用支持参数 - if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { - if (StringUtils.isNotEmpty(e.getPlanParams())) { - applyStartBO.setPlanParams(e.getPlanParams()); - List paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); - applyStartBO.setParams(paramList); - } + applyPlanList.forEach(e -> { + List runRebotList = getRunRebot(listRebotVos, e.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return; + } + ListRebotVO rebot = runRebotList.get(0); + log.debug("指定时间执行 执行时间:" + e.getExcTime()); + if (ids.contains(e.getId())) { + return; + } + if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { + ApplyStartBO applyStartBO = new ApplyStartBO(); + applyStartBO.setRobotUuid(e.getAppId()); + applyStartBO.setAccountName(rebot.getRobotClientName()); + applyStartBO.setManualTime(e.getManualTime()); + //high 高 middle 中 low 低 + applyStartBO.setPriority("high"); + // 如果应用支持参数 + if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { + if (StringUtils.isNotEmpty(e.getPlanParams())) { + applyStartBO.setPlanParams(e.getPlanParams()); + List paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); + applyStartBO.setParams(paramList); } - try { - JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); - ApplyPlan applyPlan = new ApplyPlan(); - applyPlan.setId(e.getId()); - applyPlan.setUpdateBy("系统修改"); - applyPlan.setUpdateTime(new Date()); - applyPlan.setTaskUuid(jobStartVO.getJobUuid()); - applyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); - this.updateById(applyPlan); - Rebot updateRebot = new Rebot(); - updateRebot.setUpdateBy("系统修改"); - updateRebot.setUpdateTime(new Date()); - updateRebot.setStatus(RebotStatus.RUNNING.getKey()); - if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { - log.debug("applyPlanList:" + applyPlanList.size()); - ids.add(e.getId()); - } - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); + } + try { + JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); + ApplyPlan applyPlan = new ApplyPlan(); + applyPlan.setId(e.getId()); + applyPlan.setUpdateBy("系统修改"); + applyPlan.setUpdateTime(new Date()); + applyPlan.setTaskUuid(jobStartVO.getJobUuid()); + applyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); + this.updateById(applyPlan); + Rebot updateRebot = new Rebot(); + updateRebot.setUpdateBy("系统修改"); + updateRebot.setUpdateTime(new Date()); + updateRebot.setStatus(RebotStatus.RUNNING.getKey()); + if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { + log.debug("applyPlanList:" + applyPlanList.size()); + ids.add(e.getId()); } + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); } - }); + } }); } } catch (InterruptedException e) { @@ -348,17 +414,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } List ids = new ArrayList<>(); execApplyPlan.forEach(e -> { if (listRebotVos.isEmpty()) { return; } + + List runRebotList = getRunRebot(listRebotVos, e.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return; + } + ListRebotVO rebot = runRebotList.get(0); log.debug("机器人表达式执行调度日志" + rebot.getRobotClientName() + "调度" + e.getAppName() + "应用,排除的应用id为" + ids.toString()); if (ids.contains(e.getId())) { @@ -540,6 +608,13 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } - // 获取每个部门优先级最高的计划 List applyPlans = new ArrayList<>(); applyPlanMap.forEach((k, v) -> { @@ -625,20 +694,22 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos, runApplyPlan.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return false; } - applyPlan = applyPlans.get(0); + applyStartBO = new ApplyStartBO(); - applyStartBO.setRobotUuid(applyPlan.getAppId()); + applyStartBO.setRobotUuid(runApplyPlan.getAppId()); //high 高 middle 中 low 低 applyStartBO.setPriority("high"); - applyStartBO.setAccountName(listRebotVO.getRobotClientName()); + applyStartBO.setAccountName(runRebotList.get(0).getRobotClientName()); // 如果应用支持参数 - if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { - List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyPlan.getAppId()).list(); + if (!Objects.isNull(runApplyPlan.getSupportParam()) && runApplyPlan.getSupportParam() == 1) { + List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, runApplyPlan.getAppId()).list(); if (!list.isEmpty()) { List robotParamList = list.stream().map(e -> { ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); @@ -655,23 +726,23 @@ public class ApplyPlanServiceImpl extends ServiceImpl getRunRebot(List listRebotVos){ - // 查询应用是否有指定机器人,没有则随机指派 - List rebotList = applyRebotService.list(new LambdaQueryWrapper().eq(ApplyRebot::getApplyId, applyStartBO.getRobotUuid())).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); - // 是否继续执行 - List runRebotList = new ArrayList<>(); - // 如果查到关系,则该应用指定了机器人 - if(!rebotList.isEmpty()){ - // 遍历可用机器人 - listRebotVos.forEach(e->{ - // 如果有指定可用 - if(rebotList.contains(e.getRobotClientName())){ - runRebotList.add(e); - } - }); - }else{ - runRebotList.addAll(listRebotVos); - } - if(runRebotList.isEmpty()){ - return runRebotList; - }else{ - return null; - } - } - + private List getRunRebot(List listRebotVos, String appId) { + // 查询应用是否有指定机器人,没有则随机指派 + List rebotList = applyRebotService.list(new LambdaQueryWrapper().eq(ApplyRebot::getApplyId, appId)).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); + // 是否继续执行 + List runRebotList = new ArrayList<>(); + // 如果查到关系,则该应用指定了机器人 + if (!rebotList.isEmpty()) { + // 遍历可用机器人 + listRebotVos.forEach(e -> { + // 如果有指定可用 + if (rebotList.contains(e.getRobotClientName())) { + runRebotList.add(e); + } + }); + } else { + runRebotList.addAll(listRebotVos); + } + if (!runRebotList.isEmpty()) { + return runRebotList; + } else { + return null; + } + } @Override diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java index f3df1e7..05f9810 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java @@ -183,6 +183,9 @@ public class ApplyServiceImpl extends ServiceImpl implements if ("2".equals(plan.getExcType())) { // 获取执行日志 List applyPlanLogs = planLogMap.get(e.getAppId()); + if(null == applyPlanLogs){ + return; + } // 日志总计节约时间 AtomicReference logPlanTime = new AtomicReference<>(BigDecimal.ZERO); applyPlanLogs.forEach(log -> {