初始代码
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-boot-common</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-common-scheduletask</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-scheduletask-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-scheduletask-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.yunzhupaas.scheduletask.rest;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.scheduletask.config.RegisterAddressConfig;
|
||||
import com.yunzhupaas.scheduletask.entity.*;
|
||||
import com.yunzhupaas.scheduletask.model.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class RestScheduleTaskUtil {
|
||||
|
||||
private static RegisterAddressConfig registerAddressConfig;
|
||||
|
||||
static {
|
||||
RegisterAddressConfig bean = SpringContext.getBean(RegisterAddressConfig.class);
|
||||
if (bean == null) {
|
||||
log.error("RegisterAddressConfig Bean未加载成功");
|
||||
}
|
||||
registerAddressConfig = bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取执行器列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<HandlerNameEntity> getHandlerList() {
|
||||
String handlerList = cn.hutool.http.HttpUtil.get(registerAddressConfig.getHandle_query_address());
|
||||
if (handlerList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return JsonUtil.getJsonToList(handlerList, HandlerNameEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过任务id获取日志列表
|
||||
*
|
||||
* @param id 任务id
|
||||
* @param userInfo
|
||||
* @param taskPage 分页参数
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getLogList(String id, UserInfo userInfo, TaskPage taskPage) {
|
||||
String param = taskPage.getRunResult() == null ? "&runResult="
|
||||
: "&runResult=" + taskPage.getRunResult().toString();
|
||||
String timeSelect = "";
|
||||
if (ObjectUtil.isNotNull(taskPage.getStartTime()) || ObjectUtil.isNotNull(taskPage.getEndTime())) {
|
||||
timeSelect = "&startTime=" + taskPage.getStartTime()
|
||||
+ "&endTime=" + taskPage.getEndTime();
|
||||
}
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getLog_query_address() + "/" + id
|
||||
+ "?currentPage=" + taskPage.getCurrentPage()
|
||||
+ "&pageSize=" + taskPage.getPageSize()
|
||||
+ "&sort=" + taskPage.getSort()
|
||||
+ "&sidx=" + taskPage.getSidx() + param + timeSelect,
|
||||
"POST", JsonUtil.getObjectToString(userInfo));
|
||||
JSONObject jsonObject = (JSONObject) get.get("data");
|
||||
List<TaskLogVO> data = JsonUtil.getJsonToList(jsonObject.get("list"), TaskLogVO.class);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(jsonObject.get("pagination"), PaginationVO.class);
|
||||
jsonObject.put("list", data);
|
||||
jsonObject.put("pagination", page);
|
||||
get.put("data", jsonObject);
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页数据
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getList(Pagination pagination, UserInfo userInfo) {
|
||||
JSONObject get = null;
|
||||
try {
|
||||
get = HttpUtil.httpRequest(registerAddressConfig.getTask_list_address()
|
||||
+ "?currentPage=" + pagination.getCurrentPage()
|
||||
+ "&pageSize=" + pagination.getPageSize()
|
||||
+ "&keyword=" + URLEncoder.encode(pagination.getKeyword(), "utf-8"),
|
||||
"POST", JsonUtil.getObjectToString(userInfo));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) get.get("data");
|
||||
List<TaskVO> data = JsonUtil.getJsonToList(jsonObject.get("list"), TaskVO.class);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(jsonObject.get("pagination"), PaginationVO.class);
|
||||
jsonObject.put("list", data);
|
||||
jsonObject.put("pagination", page);
|
||||
get.put("data", jsonObject);
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过任务id获取任务详情
|
||||
*
|
||||
* @param id 任务id
|
||||
* @return
|
||||
*/
|
||||
public static TimeTaskEntity getInfo(String id, UserInfo userInfo) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_info_address() + "?taskId=" + id,
|
||||
"POST", JsonUtil.getObjectToString(userInfo));
|
||||
return JsonUtil.getJsonToBean(get, TimeTaskEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存任务调度
|
||||
*
|
||||
* @param taskCrForm
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject create(TaskCrForm taskCrForm) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_save_address(),
|
||||
"POST", JsonUtil.getObjectToString(taskCrForm));
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日程任务调度
|
||||
*
|
||||
* @param taskCrForm
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject schedule(TaskCrForm taskCrForm) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_save_address() + "/schedule",
|
||||
"POST", JsonUtil.getObjectToString(taskCrForm));
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改任务调度
|
||||
*
|
||||
* @param id
|
||||
* @param taskUpForm
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject update(String id, TaskUpForm taskUpForm) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_update_address() + "/" + id,
|
||||
"PUT", JsonUtil.getObjectToString(taskUpForm));
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务调度
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject delete(String id, UserInfo userInfo) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_remove_address() + "/" + id,
|
||||
"POST", JsonUtil.getObjectToString(userInfo));
|
||||
return get;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动任务调度
|
||||
*
|
||||
* @param updateTaskModel
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject updateTask(UpdateTaskModel updateTaskModel) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getTask_startOrRemove_address(),
|
||||
"POST", JsonUtil.getObjectToString(updateTaskModel));
|
||||
return get;
|
||||
}
|
||||
|
||||
public static XxlJobInfo getInfoByTaskId(String taskId) {
|
||||
JSONObject get = HttpUtil.httpRequest(registerAddressConfig.getJob_info_address() + "?taskId=" + taskId,
|
||||
"GET", null);
|
||||
return JsonUtil.getJsonToBean(get, XxlJobInfo.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user