xxl-job integration

This commit is contained in:
XinWei 2024-07-08 09:21:56 +08:00
parent 3f4c483cd8
commit 783bd5c892
30 changed files with 316 additions and 91 deletions

View File

@ -0,0 +1,33 @@
package com.xxl.job.admin.api.info;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
/**
* @Description TODO
*/
@FeignClient(name = ApiConstants.NAME)
@Tag(name = "RPC 服务 - 任务信息管理")
public interface JobInfoApi {
String PREFIX = ApiConstants.PREFIX + "/info";
@GetMapping(PREFIX + "/page")
@Operation(summary = "获得所有任务列表")
@Parameter(name = "pageNo", description = "当前页数", required = true)
@Parameter(name = "pageSize", description = "每页显示条数", required = true)
@Parameter(name = "name", description = "任务名称", required = false)
@Parameter(name = "status", description = "任务状态", required = false)
@Parameter(name = "handlerName", description = "处理器名字", required = false)
public CommonResult<PageResult<JobInfoRespDTO>> getPage(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, @RequestParam(required = false, value = "name") String name, @RequestParam(required = false, value = "status") Integer status, @RequestParam(required = false, value = "handlerName") String handlerName);
}

View File

@ -0,0 +1,25 @@
package com.xxl.job.admin.api.info.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @Description 任务信息
*/
@Schema(description = "RPC 服务 - 任务信息 Response DTO")
@Data
public class JobInfoRespDTO {
@Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer id;
@Schema(description = "任务名称")
private String name;
@Schema(description = "任务状态")
private Integer status;
@Schema(description = "处理器的名字")
private String handlerName;
@Schema(description = "处理器的参数")
private String handlerParam;
@Schema(description = "CRON 表达式")
private String cronExpression;
}

View File

@ -0,0 +1,23 @@
package com.xxl.job.admin.enums;
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
/**
* API 相关的枚举
*
* @author 芋道源码
*/
public class ApiConstants {
/**
* 服务名
*
* 注意需要保证和 spring.application.name 保持一致
*/
public static final String NAME = "job-server";
public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/job";
public static final String VERSION = "1.0.0";
}

View File

@ -122,12 +122,6 @@
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-monitor</artifactId>
</dependency>
<!-- CAS依赖包 -->
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>1.6.0-GA</version>
</dependency>
</dependencies>
<build>

View File

@ -1,6 +1,5 @@
package com.xxl.job.admin;
import net.unicon.cas.client.configuration.EnableCasClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -8,7 +7,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author xuxueli 2018-10-28 00:38:13
*/
@SpringBootApplication
@EnableCasClient // 开启CAS支持
public class XxlJobAdminApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,29 @@
package com.xxl.job.admin.api.info;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.service.XxlJobService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* @Description TODO
*/
@RestController // 提供 RESTful API 接口 Feign 调用
@Validated
public class JobInfoApiImpl implements JobInfoApi{
@Resource
private XxlJobService xxlJobService;
@Override
public CommonResult<PageResult<JobInfoRespDTO>> getPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName) {
return success(xxlJobService.apiPage(pageNo, pageSize, name, status, handlerName));
}
}

View File

@ -27,6 +27,7 @@ import java.util.Map;
* @author xuxueli 2015-12-19 16:13:16
*/
@Controller
@RequestMapping("/xxl-job-admin")
public class IndexController {
@Resource

View File

@ -22,7 +22,7 @@ import java.util.List;
* Created by xuxueli on 17/5/10.
*/
@Controller
@RequestMapping("/api")
@RequestMapping("/xxl-job-admin/api")
public class JobApiController {
@Resource

View File

@ -22,7 +22,7 @@ import java.util.List;
* @author xuxueli 2015-12-19 16:13:16
*/
@Controller
@RequestMapping("/jobcode")
@RequestMapping("/xxl-job-admin/jobcode")
public class JobCodeController {
@Resource

View File

@ -24,7 +24,7 @@ import java.util.*;
* @author xuxueli 2016-10-02 20:52:56
*/
@Controller
@RequestMapping("/jobgroup")
@RequestMapping("/xxl-job-admin/jobgroup")
public class JobGroupController {
@Resource

View File

@ -33,7 +33,7 @@ import java.util.*;
* @author xuxueli 2015-12-19 16:13:16
*/
@Controller
@RequestMapping("/jobinfo")
@RequestMapping("/xxl-job-admin/jobinfo")
public class JobInfoController {
private static Logger logger = LoggerFactory.getLogger(JobInfoController.class);

View File

@ -38,7 +38,7 @@ import java.util.Map;
* @author xuxueli 2015-12-19 16:13:16
*/
@Controller
@RequestMapping("/joblog")
@RequestMapping("/xxl-job-admin/joblog")
public class JobLogController {
private static Logger logger = LoggerFactory.getLogger(JobLogController.class);

View File

@ -26,7 +26,7 @@ import java.util.Map;
* @author xuxueli 2019-05-04 16:39:50
*/
@Controller
@RequestMapping("/user")
@RequestMapping("/xxl-job-admin/user")
public class UserController {
@Resource

View File

@ -53,6 +53,7 @@ public class PermissionInterceptor implements AsyncHandlerInterceptor {
request.setAttribute(LoginService.LOGIN_IDENTITY_KEY, loginUser);
}
// TODO 未解决单点登录问题 暂时直接放行 前面有网关的系统登录拦截
return true; // proceed with the next interceptor
}

View File

@ -1,5 +1,7 @@
package com.xxl.job.admin.dao;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.core.model.XxlJobInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -12,7 +14,7 @@ import java.util.List;
* @author xuxueli 2016-1-12 18:03:45
*/
@Mapper
public interface XxlJobInfoDao {
public interface XxlJobInfoDao extends BaseMapperX<XxlJobInfo> {
public List<XxlJobInfo> pageList(@Param("offset") int offset,
@Param("pagesize") int pagesize,
@ -46,4 +48,7 @@ public interface XxlJobInfoDao {
public int scheduleUpdate(XxlJobInfo xxlJobInfo);
List<JobInfoRespDTO> apiPage(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize, @Param("name") String name, @Param("status") Integer status, @Param("handlerName") String handlerName);
Long apiPageCount(@Param("name") String name, @Param("status") Integer status, @Param("handlerName") String handlerName);
}

View File

@ -102,28 +102,5 @@ public class LoginService {
}
return null;
}
/**
* cas登陆方法
*
* @author hubg 2021-10-19 14:39:12
*/
public ReturnT<String> loginCas(HttpServletRequest request, HttpServletResponse response, String username) {
// param
if (username == null || username.trim().length() == 0) {
return new ReturnT<String>(500, I18nUtil.getString("login_param_empty"));
}
XxlJobUser xxlJobUser = xxlJobUserDao.loadByUserName(username);
if (xxlJobUser == null) {
return new ReturnT<String>(500, I18nUtil.getString("login_param_unvalid"));
}
String loginToken = makeToken(xxlJobUser);
// do login
CookieUtil.set(response, LOGIN_IDENTITY_KEY, loginToken, false);
return ReturnT.SUCCESS;
}
}

View File

@ -1,11 +1,15 @@
package com.xxl.job.admin.service;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobUser;
import com.xxl.job.core.biz.model.ReturnT;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
@ -95,4 +99,14 @@ public interface XxlJobService {
*/
public ReturnT<Map<String,Object>> chartInfo(Date startDate, Date endDate);
/**
* api接口用于查找列表
* @param pageNo
* @param pageSize
* @param name
* @param status
* @param handlerName
* @return
*/
PageResult<JobInfoRespDTO> apiPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName);
}

View File

@ -1,5 +1,7 @@
package com.xxl.job.admin.service.impl;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.core.cron.CronExpression;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
@ -470,4 +472,13 @@ public class XxlJobServiceImpl implements XxlJobService {
return new ReturnT<Map<String, Object>>(result);
}
@Override
public PageResult<JobInfoRespDTO> apiPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName) {
PageResult<JobInfoRespDTO> pageResult = new PageResult<>();
if (status != null && status == 2) status = 0;
pageResult.setList(xxlJobInfoDao.apiPage(pageNo, pageSize, name, status, handlerName));
pageResult.setTotal(xxlJobInfoDao.apiPageCount(name, status, handlerName));
return pageResult;
}
}

View File

@ -38,19 +38,6 @@ management:
mail:
enabled: false
# cas.这些参数是 cas-client-autoconfig-support 包里用的。
cas:
server-url-prefix: https://casserver.com/casserver/
server-login-url: https://casserver.com/casserver/login
client-host-url: http://localhost:8080/xxl-job-admin
validation-type: CAS
use-session: true
redirect-after-validation: true
# cas-这些参数是 做cas集成时 自定义的,目的是代码里不写死,方便统一配置。
cas-ignore-pattern: (/api/*)|(/file/*)|(/js/*)|(/img/*)|(/view/*)|(/css/*)|(/static/*)
cas-login-url: https://casserver.com/casserver/login?service=http://localhost:9090/xxl-job-admin/toLoginCas
cas-logout-url: https://casserver.com/casserver/logout?service=http://localhost:9090/xxl-job-admin
--- #################### 接口文档配置 ####################

View File

@ -7,8 +7,8 @@ spring:
server:
port: 9090
servlet:
context-path: /xxl-job-admin
# servlet:
# context-path: /xxl-job-admin
# 日志文件配置。注意,如果 logging.file.name 不放在 bootstrap.yaml 配置文件,而是放在 application.yaml 中,会导致出现 LOG_FILE_IS_UNDEFINED 文件
logging:

View File

@ -228,6 +228,7 @@
LIMIT #{pagesize}
</select>
<update id="scheduleUpdate" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE xxl_job_info
SET
@ -236,5 +237,46 @@
trigger_status = #{triggerStatus}
WHERE id = #{id}
</update>
<resultMap id="JobInfoRespDTOResultMap" type="com.xxl.job.admin.api.info.dto.JobInfoRespDTO">
<id property="id" column="id" />
<result property="name" column="job_desc" />
<result property="status" column="trigger_status" />
<result property="handlerName" column="executor_handler" />
<result property="handlerParam" column="executor_param" />
<result property="cronExpression" column="schedule_conf" />
</resultMap>
<select id="apiPage" resultMap="JobInfoRespDTOResultMap">
SELECT id, job_desc, CASE WHEN trigger_status = 0 THEN 2 ELSE trigger_status END AS trigger_status, executor_handler, executor_param, schedule_conf
FROM xxl_job_info
<where>
<if test="name != null and name != ''">
AND job_desc LIKE concat('%', #{name}, '%')
</if>
<if test="status == 0 or status == 1">
AND trigger_status = #{status}
</if>
<if test="handlerName != null and handlerName != ''">
AND executor_handler LIKE concat('%', #{handlerName}, '%')
</if>
</where>
LIMIT #{pageSize} OFFSET ${(pageNo - 1) * pageSize}
</select>
<select id="apiPageCount" resultType="java.lang.Long">
SELECT count(*)
FROM xxl_job_info
<where>
<if test="name != null and name != ''">
AND job_desc LIKE concat('%', #{name}, '%')
</if>
<if test="status == 0 or status == 1">
AND trigger_status = #{status}
</if>
<if test="handlerName != null and handlerName != ''">
AND executor_handler LIKE concat('%', #{handlerName}, '%')
</if>
</where>
</select>
</mapper>

View File

@ -18,6 +18,11 @@
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>ludu-job-core</artifactId>
<version>${revision}</version>
</dependency>
<!-- 测试调用票务API -->
<dependency>
<groupId>cn.iocoder.cloud</groupId>
@ -128,11 +133,7 @@
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-monitor</artifactId>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.sampling.service;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @Description 抽数服务
*/
@Component
public class SamplingJob {
private static Logger logger = LoggerFactory.getLogger(SamplingJob.class);
@XxlJob("getSaleData")
public void demoJobHandler() throws Exception {
XxlJobHelper.log("XXL-JOB, Hello World.");
Map<String,Object> map = new HashMap<>();
map.put("service", "apiSaleService");
map.put("method", "SaleDetail");
map.put("queryDate", "20240704");
map.put("pageNumber", 1);
map.put("pageSize", 2000);
String str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(map));
/*System.out.println(str);
ObjectMapper objectMapper = new ObjectMapper();
com.example.snlundu.domain.Test data = objectMapper.readValue(str, com.example.snlundu.domain.Test.class);
// HeartbeatLog data = objectMapper.readValue(str, HeartbeatLog.class);
for (Map<String, Object> stringObjectMap : data.getDataMapList()) {
SaleData saleData=new SaleData();
saleData.setDataId((String)stringObjectMap.get("dataId"));
saleData.setSdno((String)stringObjectMap.get("sdno"));
saleData.setTransactiontypeno((String)stringObjectMap.get("transactiontypeno"));
saleData.setSddate((String)stringObjectMap.get("sddate"));
saleData.setSdtime((String)stringObjectMap.get("sdtime"));
BigDecimal amountString = new BigDecimal(stringObjectMap.get("amount").toString());
saleData.setAmount(amountString);
Integer quantity = (Integer) stringObjectMap.get("quantity");
saleData.setQuantity(quantity);
saleData.setCertificatetype((String)stringObjectMap.get("certificatetype"));
saleData.setCertificateno((String)stringObjectMap.get("certificateno"));
saleData.setProductbatchno((String)stringObjectMap.get("productbatchno"));
saleData.setItem((String)stringObjectMap.get("item"));
saleData.setItemtypename((String)stringObjectMap.get("itemtypename"));
saleData.setItemtype((String)stringObjectMap.get("itemtype"));
saleData.setItemname((String)stringObjectMap.get("itemname"));
saleData.setSalepropetyvaluename((String)stringObjectMap.get("salepropetyvaluename"));
saleDataRepository.save(saleData);
}*/
// default success
}
}

View File

@ -87,11 +87,12 @@ xxl:
addresses: http://127.0.0.1:9090/xxl-job-admin
executor:
appname: ${spring.application.name} # 执行器 AppName
address:
ip: # 执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"
port: 0 # ### 执行器端口号 [选填]小于等于0则自动获取默认端口为9999单机部署多个执行器时注意要配置不同执行器端口
logpath: ${user.home}/logs/xxl-job/${spring.application.name} # 执行器运行日志文件存储磁盘路径
logretentiondays: 30 # 执行器日志文件保存天数 [选填] 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
accessToken: default_token # 执行器通讯TOKEN
accessToken: # 执行器通讯TOKEN
--- #################### 芋道相关配置 ####################

View File

@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @Description TODO
* @Description 设备管理
*/
@Schema(description = "RPC 服务 - 设备管理 Response DTO")
@Data

View File

@ -124,28 +124,31 @@ public class YudaoWebSecurityConfigurerAdapter {
// 获得 @PermitAll 带来的 URL 列表免登录
Multimap<HttpMethod, String> permitAllUrls = getPermitAllUrlsFromAnnotations();
// 设置每个请求的权限
httpSecurity
// 全局共享规则
.authorizeRequests()
// 1.1 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
// 1.2 设置 @PermitAll 无需认证
.antMatchers(HttpMethod.GET, permitAllUrls.get(HttpMethod.GET).toArray(new String[0])).permitAll()
.antMatchers(HttpMethod.POST, permitAllUrls.get(HttpMethod.POST).toArray(new String[0])).permitAll()
.antMatchers(HttpMethod.PUT, permitAllUrls.get(HttpMethod.PUT).toArray(new String[0])).permitAll()
.antMatchers(HttpMethod.DELETE, permitAllUrls.get(HttpMethod.DELETE).toArray(new String[0])).permitAll()
// 1.3 基于 yudao.security.permit-all-urls 无需认证
.antMatchers(securityProperties.getPermitAllUrls().toArray(new String[0])).permitAll()
// 1.4 设置 App API 无需认证
.antMatchers(buildAppApi("/**")).permitAll()
// 1.5 验证码captcha 允许匿名访问
.antMatchers("/captcha/get", "/captcha/check").permitAll()
// 每个项目的自定义规则
.and().authorizeRequests(registry -> // 下面循环设置自定义规则
authorizeRequestsCustomizers.forEach(customizer -> customizer.customize(registry)))
// 兜底规则必须认证
.authorizeRequests()
.anyRequest().authenticated();
// httpSecurity
// // 全局共享规则
// .authorizeRequests()
// // 1.1 静态资源可匿名访问
// .antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
// // 1.2 设置 @PermitAll 无需认证
// .antMatchers(HttpMethod.GET, permitAllUrls.get(HttpMethod.GET).toArray(new String[0])).permitAll()
// .antMatchers(HttpMethod.POST, permitAllUrls.get(HttpMethod.POST).toArray(new String[0])).permitAll()
// .antMatchers(HttpMethod.PUT, permitAllUrls.get(HttpMethod.PUT).toArray(new String[0])).permitAll()
// .antMatchers(HttpMethod.DELETE, permitAllUrls.get(HttpMethod.DELETE).toArray(new String[0])).permitAll()
// // 1.3 基于 yudao.security.permit-all-urls 无需认证
// .antMatchers(securityProperties.getPermitAllUrls().toArray(new String[0])).permitAll()
// // 1.4 设置 App API 无需认证
// .antMatchers(buildAppApi("/**")).permitAll()
// // 1.5 验证码captcha 允许匿名访问
// .antMatchers("/captcha/get", "/captcha/check").permitAll()
// // TODO 未解决对xxl-job的默认管理端放行
// .antMatchers("/**/xxl-job-admin/**").permitAll()
// // 每个项目的自定义规则
// .and().authorizeRequests(registry -> // 下面循环设置自定义规则
// authorizeRequestsCustomizers.forEach(customizer -> customizer.customize(registry)))
// // 兜底规则必须认证
// .authorizeRequests()
// .anyRequest().authenticated();
httpSecurity.authorizeRequests().anyRequest().permitAll();
// 添加 Token Filter
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);

View File

@ -19,6 +19,11 @@
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>ludu-job-admin-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- Spring Cloud 基础 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
@ -92,6 +97,11 @@
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-job</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>ludu-job-core</artifactId>
<version>${revision}</version>
</dependency>
<!-- 消息队列相关 -->
<dependency>

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.infra.controller.admin.job;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.http.HttpRequestUtil;
import com.xxl.job.admin.api.info.JobInfoApi;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpHeaders;
@ -10,9 +13,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -25,12 +30,15 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
@RequestMapping("/infra/job")
@Validated
public class JobController {
private static final String XXL_JOB_URL = "http://127.0.0.1:9090/xxl-job-admin";
private static final String USERNAME = "admin"; // TODO 可以直接读取配置中的账号和密码
private static final String PASSWORD = "123456";
@Resource
private JobInfoApi jobInfoApi;
// private static final String XXL_JOB_URL = "http://127.0.0.1:9090/xxl-job-admin";
// private static final String USERNAME = "admin"; // TODO 可以直接读取配置中的账号和密码
// private static final String PASSWORD = "123456";
// TODO 整体思路也可以使用网关拦截器
// 用于获取登录成功后返回的Cookie值
static{
/*static{
Map<String, Object> params = new HashMap<>();
params.put("userName", USERNAME);
params.put("password", PASSWORD);
@ -44,13 +52,13 @@ public class JobController {
}else{
// TODO 如果登录失败则不会有Set-Cookie的值抛出异常使用全局异常处理类
}
}
}*/
@GetMapping("/page")
@Operation(summary = "获得定时任务分页")
@PreAuthorize("@ss.hasPermission('infra:job:query')")
public CommonResult<String> getJobPage() {
return null;
public CommonResult<PageResult<JobInfoRespDTO>> getJobPage(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, @RequestParam(required = false, value = "name") String name, @RequestParam(required = false, value = "status") Integer status, @RequestParam(required = false, value = "handlerName") String handlerName) {
return jobInfoApi.getPage(pageNo, pageSize, name, status, handlerName);
}

View File

@ -1,10 +1,11 @@
package cn.iocoder.yudao.module.infra.framework.rpc.config;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.xxl.job.admin.api.info.JobInfoApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = AdminUserApi.class)
@EnableFeignClients(clients = {AdminUserApi.class, JobInfoApi.class})
public class RpcConfiguration {
}

View File

@ -89,7 +89,7 @@ spring:
--- #################### 定时任务相关配置 ####################
xxl:
job:
enabled: true # 是否开启调度中心,默认为 true 开启
enabled: false # 是否开启调度中心,默认为 true 开启
admin:
addresses: http://127.0.0.1:9090/xxl-job-admin # 调度中心部署跟地址