Przeglądaj źródła

调整细节,增加停止按钮

pull/4/head
lcr 5 miesięcy temu
rodzic
commit
2c397d5973
10 zmienionych plików z 105 dodań i 71 usunięć
  1. +4
    -0
      ruoyi-admin/src/main/resources/application-dev.yml
  2. +8
    -4
      ruoyi-admin/src/main/resources/application-test.yml
  3. +0
    -2
      ruoyi-admin/src/main/resources/application.yml
  4. +1
    -1
      ruoyi-admin/src/main/resources/logback.xml
  5. +10
    -0
      ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java
  6. +8
    -0
      ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/ApplyStartBO.java
  7. +8
    -0
      ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java
  8. +53
    -63
      ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java
  9. +12
    -0
      ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java
  10. +1
    -1
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

+ 4
- 0
ruoyi-admin/src/main/resources/application-dev.yml Wyświetl plik

@@ -1,3 +1,7 @@
# 项目相关配置
ruoyi:
# 文件路径 示例( Windows配置D:/poject,Linux配置 /home/poject)
profile: E:\poject
# Spring配置 数据源配置
spring:
# redis 配置


+ 8
- 4
ruoyi-admin/src/main/resources/application-test.yml Wyświetl plik

@@ -1,3 +1,7 @@
# 项目相关配置
ruoyi:
# 文件路径 示例( Windows配置D:/poject,Linux配置 /home/poject)
profile: /home/pojectFile
# Spring配置 数据源配置
spring:
# redis 配置
@@ -35,9 +39,9 @@ spring:
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
url:
username:
password:
# 初始连接数
initialSize: 5
# 最小连接池数量
@@ -57,7 +61,7 @@ spring:
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
webStatFilter:
webStatFilter:
enabled: true
statViewServlet:
enabled: true


+ 0
- 2
ruoyi-admin/src/main/resources/application.yml Wyświetl plik

@@ -8,8 +8,6 @@ ruoyi:
copyrightYear: 2023
# 实例演示开关
demoEnabled: true
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
profile: E:\poject
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证


+ 1
- 1
ruoyi-admin/src/main/resources/logback.xml Wyświetl plik

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="/poject/logs" />
<property name="log.path" value="logs" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />



+ 10
- 0
ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java Wyświetl plik

@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

import com.ruoyi.business.domain.bo.AddApplyPlanBO;
import com.ruoyi.business.domain.bo.JobQueryBO;
import com.ruoyi.common.utils.bean.BeanUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -43,6 +44,15 @@ public class ApplyPlanController extends BaseController
@Autowired
private IApplyPlanService applyPlanService;

/**
* 查询应用执行计划管理列表
*/
@ApiOperation(value="停止计划运行", httpMethod = "POST", response = ApplyPlan.class)
@PostMapping("/stopRun")
public AjaxResult stopRun(@RequestBody JobQueryBO jobQueryBO) throws IllegalAccessException {
return toAjax(applyPlanService.stopRun(jobQueryBO));
}

/**
* 查询应用执行计划管理列表
*/


+ 8
- 0
ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/ApplyStartBO.java Wyświetl plik

@@ -28,6 +28,14 @@ import java.util.List;
@ApiModel(value = "ApplyStartBO", description = "启动应用")
public class ApplyStartBO {
private static final long serialVersionUID = 1L;

/**
* 冗余
*/
@Excel(name = "计划名称")
@ApiModelProperty(name="planName",value = "计划名称")
private String planName;

/** 预计人工耗时 */
@Excel(name = "预计人工耗时")
@ApiModelProperty(name="manualTime",value = "预计人工耗时")


+ 8
- 0
ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java Wyświetl plik

@@ -17,6 +17,14 @@ import com.ruoyi.business.domain.vo.JobQueryVO;
*/
public interface IApplyPlanService extends IService<ApplyPlan> {

/**
* 停止运行
*
* @param
* @return
*/
boolean stopRun(JobQueryBO jobQueryBO) throws IllegalAccessException;

/**
* 更新计划应用执行结果
*


+ 53
- 63
ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java Wyświetl plik

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


+ 12
- 0
ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java Wyświetl plik

@@ -36,6 +36,8 @@ public class YinDaoHttpUtils {
private static final String APP_LIST = REQUEST_PREFIX + "/app/open/query/list";
// 启动应用
private static final String APP_START = REQUEST_PREFIX + "/dispatch/v2/job/start";
// 停止应用
private static final String APP_STOP = REQUEST_PREFIX + "/dispatch/v2/job/stop";
// 查询应用运行结果
private static final String QUERY_APP_START_RESULT = REQUEST_PREFIX + "/dispatch/v2/job/query";
// 查询应用运行日志(异常时可以查询原因)
@@ -52,6 +54,16 @@ public class YinDaoHttpUtils {
return JSON.parseObject(baseDTO.getData().toString(), JobStartVO.class);
}

/**
* 启动应用
*/
public static BaseDTO appStop(JobQueryBO jobQueryBO) throws IllegalAccessException {
// 实体类转map
Map<String, Object> data = BeanToMapUtil.convertEntityToMap(jobQueryBO);
BaseDTO baseDTO = sendPost(APP_STOP, data);
return baseDTO;
}

/**
* 查询应用运行结果
*/


+ 1
- 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java Wyświetl plik

@@ -116,7 +116,7 @@ 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()
.antMatchers("/common/upload","/dev-api/profile/upload/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()
.and()


Ładowanie…
Anuluj
Zapisz