diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index bebed19..1e7870e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -9,7 +9,7 @@ ruoyi: # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) - profile: D:/poject/log/uploadPath + profile: E:\poject # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 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 ccaf0e2..146fe8c 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 @@ -84,6 +84,11 @@ public class ApplyPlan extends BaseEntity @ApiModelProperty(name="planParams",value = "计划参数") private String planParams; + /** 输出参数 */ + @Excel(name = "输出参数") + @ApiModelProperty(name="outParam",value = "输出参数") + private String outParam; + /** 等待超时时间 */ @Excel(name = "等待超时时间") @ApiModelProperty(name="waitTimeout",value = "等待超时时间") diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ResourceLibrary.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ResourceLibrary.java index c88de70..f5a0653 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ResourceLibrary.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ResourceLibrary.java @@ -55,6 +55,11 @@ public class ResourceLibrary extends BaseEntity @ApiModelProperty(name="resourceName",value = "资源键") private String resourceName; + /** 所属应用id */ + @Excel(name = "所属应用id") + @ApiModelProperty(name="appId",value = "所属应用id") + private String appId; + /** 所属应用名称 */ @Excel(name = "所属应用名称") @ApiModelProperty(name="appName",value = "所属应用名称") @@ -65,7 +70,10 @@ public class ResourceLibrary extends BaseEntity @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/domain/vo/JobQueryVO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java index 1676add..40f817c 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/JobQueryVO.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.util.Date; +import java.util.List; /** * 查询job响应 @@ -72,7 +73,7 @@ public class JobQueryVO { /** * 应用运行参数 */ - private RobotParam robotParams; + private Param robotParams; /** * 机器人账号 @@ -88,11 +89,13 @@ public class JobQueryVO { */ private String robotClientName; + + /** * 应用运行参数 */ @Data - private static class RobotParam { + public static class RobotParam { // 参数名 private String name; // 参数值 @@ -101,4 +104,16 @@ public class JobQueryVO { private String type; } + + /** + * 应用运行参数 + */ + @Data + public static class Param { + // 输入参数 + private List inputs; + // 输出参数 + private List outputs; + + } } \ No newline at end of file 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 a8e2172..35819e7 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 @@ -10,12 +10,14 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.ruoyi.business.domain.Apply; import com.ruoyi.business.domain.Rebot; +import com.ruoyi.business.domain.ResourceLibrary; import com.ruoyi.business.domain.bo.*; import com.ruoyi.business.domain.vo.JobQueryVO; import com.ruoyi.business.domain.vo.JobStartVO; import com.ruoyi.business.domain.vo.ListRebotVO; 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.common.annotation.DataScope; import com.ruoyi.common.enums.ExcTypeStatus; @@ -48,6 +50,9 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime).list(); + if (applyPlanList.isEmpty()) { + return false; + } + ListRebotBO listRebotBO = new ListRebotBO(); listRebotBO.setStatus(RebotStatus.IDLE.getKey()); listRebotBO.setPage(1); @@ -69,7 +79,6 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime).list(); listRebotVos.forEach(rebot -> { applyPlanList.forEach(e -> { if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { @@ -79,12 +88,20 @@ public class ApplyPlanServiceImpl extends ServiceImpl list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); - applyStartBO.setPlanParamsList(list); + // 如果应用支持参数 + if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { + // 获取参数 + List 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()) { + applyStartBO.setPlanParamsList(paramList); + } } try { JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); @@ -96,10 +113,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()).list(); + if (applyPlanList.isEmpty()) { + return false; + } + // 需要执行的计划 + List execApplyPlan = new ArrayList<>(); + applyPlanList.forEach(e -> { + try { + CronExpression cron = new CronExpression(e.getCronExpression()); + // 如果该计划没有执行过 + if (Objects.isNull(e.getLastExecTime())) { + // 判断当前时间是否满足表达式 + Date nextDate = cron.getNextValidTimeAfter(new Date()); + if (new Date().compareTo(nextDate) > -1) { + execApplyPlan.add(e); + } + } else { + // 根据表达式返回下一个执行时间 + Date nextDate = cron.getNextValidTimeAfter(e.getNextExecTime()); + if (new Date().compareTo(nextDate) > -1) { + execApplyPlan.add(e); + } + } + } catch (ParseException ex) { + log.error(e.getPlanName() + "的时间表达式错误!"); + throw new RuntimeException(ex); + } + }); + if (execApplyPlan.isEmpty()) { + log.error("没有待执行的计划"); + return false; + } + ListRebotBO listRebotBO = new ListRebotBO(); listRebotBO.setStatus(RebotStatus.IDLE.getKey()); listRebotBO.setPage(1); @@ -129,77 +180,67 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()).list(); listRebotVos.forEach(rebot -> { - applyPlanList.forEach(e -> { - // 是否满足执行条件 - boolean isExec = false; + execApplyPlan.forEach(e -> { + // 该计划满足执行条件 + 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) { + // 获取参数 + List 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()) { + applyStartBO.setPlanParamsList(paramList); + } + } + String planParams = e.getPlanParams(); + if (StringUtils.isNotEmpty(planParams)) { + JSONArray jsonArray = JSON.parseArray(planParams); + // 直接转换成List + List list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); + applyStartBO.setPlanParamsList(list); + } 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()); + // 根据表达式返回下一个执行时间 CronExpression cron = new CronExpression(e.getCronExpression()); - // 如果该计划没有执行过 + Date nextDate = null; if (Objects.isNull(e.getLastExecTime())) { - // 判断当前时间是否满足表达式 - Date nextDate = cron.getNextValidTimeAfter(new Date()); - if (new Date().compareTo(nextDate) > -1) { - isExec = true; - } + nextDate = cron.getNextValidTimeAfter(new Date()); } else { - // 根据表达式返回下一个执行时间 - Date nextDate = cron.getNextValidTimeAfter(e.getNextExecTime()); - if (new Date().compareTo(nextDate) > -1) { - isExec = true; - } + nextDate = cron.getNextValidTimeAfter(e.getLastExecTime()); } - } catch (ParseException ex) { - log.error(e.getPlanName() + "的时间表达式错误!"); - throw new RuntimeException(ex); - } - - // 该计划满足执行条件 - if (isExec) { - ApplyStartBO applyStartBO = new ApplyStartBO(); - applyStartBO.setRobotUuid(e.getAppId()); - applyStartBO.setAccountName(rebot.getRobotClientName()); - applyStartBO.setManualTime(e.getManualTime()); - //high 高 middle 中 low 低 - applyStartBO.setPriority("high"); - String planParams = e.getPlanParams(); - if (StringUtils.isNotEmpty(planParams)) { - JSONArray jsonArray = JSON.parseArray(planParams); - // 直接转换成List - List list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); - applyStartBO.setPlanParamsList(list); - } - 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()); - // 根据表达式返回下一个执行时间 - CronExpression cron = new CronExpression(e.getCronExpression()); - Date nextDate = null; - if (Objects.isNull(e.getLastExecTime())) { - nextDate = cron.getNextValidTimeAfter(new Date()); - } else { - nextDate = cron.getNextValidTimeAfter(e.getLastExecTime()); - } - Date date = new Date(); - applyPlan.setLastExecTime(date); - applyPlan.setNextExecTime(nextDate); - 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)){ - applyPlanList.remove(e); - } - } catch (IllegalAccessException | ParseException ex) { - throw new RuntimeException(ex); + Date date = new Date(); + applyPlan.setLastExecTime(date); + applyPlan.setNextExecTime(nextDate); + 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)) { + applyPlanList.remove(e); } + } catch (IllegalAccessException | ParseException ex) { + throw new RuntimeException(ex); } }); }); @@ -207,21 +248,6 @@ public class ApplyPlanServiceImpl extends ServiceImpl jobQueryVOS = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { ApplyPlan applyPlan = list.get(i); JobQueryBO jobQueryBO = new JobQueryBO(); @@ -265,11 +290,24 @@ 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())) { + List outputs = jobQueryVO.getRobotParams().getOutputs(); + if (null != outputs && !outputs.isEmpty()) { + JobQueryVO.RobotParam robotParam = outputs.get(0); + updateApplyPlan.setOutParam(robotParam.getValue()); + } + } + this.updateById(updateApplyPlan); } // 如果是终态改变机器人状态 @@ -299,6 +337,16 @@ public class ApplyPlanServiceImpl extends ServiceImpl> 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; + } + ListRebotBO listRebotBO = new ListRebotBO(); listRebotBO.setStatus(RebotStatus.IDLE.getKey()); listRebotBO.setPage(1); @@ -312,15 +360,6 @@ public class ApplyPlanServiceImpl extends ServiceImpl> 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) -> { @@ -336,7 +375,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl list = jsonArray.toJavaList(ApplyStartBO.RobotParam.class); - applyStartBO.setPlanParamsList(list); + // 如果应用支持参数 + if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { + // 获取参数 + List 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()) { + applyStartBO.setPlanParamsList(paramList); + } } + JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); ApplyPlan updateApplyPlan = new ApplyPlan(); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java index c8e5599..6fd5cb2 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java @@ -1,6 +1,10 @@ package com.ruoyi.business.service.impl; import java.util.List; +import java.util.Optional; + +import com.ruoyi.business.domain.Apply; +import com.ruoyi.business.service.IApplyService; import com.ruoyi.common.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -19,6 +23,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; public class ResourceLibraryServiceImpl extends ServiceImpl implements IResourceLibraryService { + @Autowired + private IApplyService applyService; /** * 查询资源库管理列表 @@ -31,4 +37,15 @@ public class ResourceLibraryServiceImpl extends ServiceImplnew RuntimeException("应用不存在")); + entity.setAppId(apply.getAppId()); + entity.setAppName(apply.getAppName()); + entity.setDeptId(apply.getDeptId()); + entity.setDeptName(apply.getDeptName()); + return super.save(entity); + } } diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml index 579a5c7..84b1305 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml @@ -110,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and support_param = #{supportParam} and dept_id = #{deptId} and dept_name like concat(#{deptName}, '%') - and version != '未发版' and apply.manual_time != null + and version != '未发版' ${params.dataScope} diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml index 52c9715..68b6c44 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml @@ -25,6 +25,8 @@ + + @@ -81,6 +83,7 @@ plan.app_type, plan.support_param, plan.plan_params, + plan.out_param, plan.wait_timeout, plan.priority, plan.exc_type, diff --git a/ruoyi-business/src/main/resources/mapper/business/ResourceLibraryMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ResourceLibraryMapper.xml index 7cb239d..c5f6f38 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ResourceLibraryMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ResourceLibraryMapper.xml @@ -15,10 +15,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + @@ -40,8 +44,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" resource_value, resource_type, resource_name, + app_id, app_name, dept_id, + dept_name, create_by, create_time, update_by, @@ -58,8 +64,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and resource_value = #{resourceValue} and resource_type = #{resourceType} and resource_name like concat(#{resourceName}, '%') + and app_id = #{appId} and app_name like concat(#{appName}, '%') and dept_id = #{deptId} + and dept_name like concat(#{deptName}, '%') \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 9130b74..151d38b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -115,6 +115,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + // 上传文件 + .antMatchers("/common/upload").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and()