From 783bd5c892812fb0d82c8abab9284c0d07e80097 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Mon, 8 Jul 2024 09:21:56 +0800 Subject: [PATCH] xxl-job integration --- .../xxl/job/admin/api/info/JobInfoApi.java | 33 ++++++++++ .../admin/api/info/dto/JobInfoRespDTO.java | 25 ++++++++ .../com/xxl/job/admin/enums/ApiConstants.java | 23 +++++++ ludu-job-admin/ludu-job-admin-biz/pom.xml | 6 -- .../xxl/job/admin/XxlJobAdminApplication.java | 2 - .../job/admin/api/info/JobInfoApiImpl.java | 29 +++++++++ .../job/admin/controller/IndexController.java | 1 + .../admin/controller/JobApiController.java | 2 +- .../admin/controller/JobCodeController.java | 2 +- .../admin/controller/JobGroupController.java | 2 +- .../admin/controller/JobInfoController.java | 2 +- .../admin/controller/JobLogController.java | 2 +- .../job/admin/controller/UserController.java | 2 +- .../interceptor/PermissionInterceptor.java | 1 + .../com/xxl/job/admin/dao/XxlJobInfoDao.java | 7 ++- .../xxl/job/admin/service/LoginService.java | 23 ------- .../xxl/job/admin/service/XxlJobService.java | 14 +++++ .../admin/service/impl/XxlJobServiceImpl.java | 11 ++++ .../src/main/resources/application.yaml | 13 ---- .../src/main/resources/bootstrap.yaml | 4 +- .../mybatis-mapper/XxlJobInfoMapper.xml | 42 +++++++++++++ .../ludu-module-sampling-biz/pom.xml | 11 ++-- .../module/sampling/service/SamplingJob.java | 61 +++++++++++++++++++ .../src/main/resources/application.yaml | 3 +- .../api/asset/dto/TicketAssetRespDTO.java | 2 +- .../YudaoWebSecurityConfigurerAdapter.java | 47 +++++++------- .../yudao-module-infra-biz/pom.xml | 10 +++ .../controller/admin/job/JobController.java | 22 ++++--- .../rpc/config/RpcConfiguration.java | 3 +- .../src/main/resources/application-local.yaml | 2 +- 30 files changed, 316 insertions(+), 91 deletions(-) create mode 100644 ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/JobInfoApi.java create mode 100644 ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/dto/JobInfoRespDTO.java create mode 100644 ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/enums/ApiConstants.java create mode 100644 ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/info/JobInfoApiImpl.java create mode 100644 ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/service/SamplingJob.java diff --git a/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/JobInfoApi.java b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/JobInfoApi.java new file mode 100644 index 000000000..abc74ca4c --- /dev/null +++ b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/JobInfoApi.java @@ -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> 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); + +} diff --git a/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/dto/JobInfoRespDTO.java b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/dto/JobInfoRespDTO.java new file mode 100644 index 000000000..de6c7ab40 --- /dev/null +++ b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/info/dto/JobInfoRespDTO.java @@ -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; + +} diff --git a/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/enums/ApiConstants.java b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/enums/ApiConstants.java new file mode 100644 index 000000000..a7cfeb973 --- /dev/null +++ b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/enums/ApiConstants.java @@ -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"; + +} diff --git a/ludu-job-admin/ludu-job-admin-biz/pom.xml b/ludu-job-admin/ludu-job-admin-biz/pom.xml index 5c2f0c8cc..5d73635c8 100644 --- a/ludu-job-admin/ludu-job-admin-biz/pom.xml +++ b/ludu-job-admin/ludu-job-admin-biz/pom.xml @@ -122,12 +122,6 @@ cn.iocoder.cloud yudao-spring-boot-starter-monitor - - - net.unicon.cas - cas-client-autoconfig-support - 1.6.0-GA - diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/XxlJobAdminApplication.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/XxlJobAdminApplication.java index 72b373c59..fce10a81a 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/XxlJobAdminApplication.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/XxlJobAdminApplication.java @@ -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) { diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/info/JobInfoApiImpl.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/info/JobInfoApiImpl.java new file mode 100644 index 000000000..23ea146e4 --- /dev/null +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/info/JobInfoApiImpl.java @@ -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> getPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName) { + return success(xxlJobService.apiPage(pageNo, pageSize, name, status, handlerName)); + } +} diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/IndexController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/IndexController.java index eb63f0bd4..f6d364d5a 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/IndexController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/IndexController.java @@ -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 diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobApiController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobApiController.java index aa51e7390..1370ea617 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobApiController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobApiController.java @@ -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 diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobCodeController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobCodeController.java index fe4a0e848..d3d7710f8 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobCodeController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobCodeController.java @@ -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 diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobGroupController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobGroupController.java index 8e0c5a4d5..5ca97419b 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobGroupController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobGroupController.java @@ -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 diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobInfoController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobInfoController.java index 516dce418..a0978d750 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobInfoController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobInfoController.java @@ -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); diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobLogController.java index bff91989e..302a88909 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -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); diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/UserController.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/UserController.java index 3f4c7559b..11a301aaa 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/UserController.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/UserController.java @@ -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 diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java index 840f0ebcf..e80202ac1 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java @@ -53,6 +53,7 @@ public class PermissionInterceptor implements AsyncHandlerInterceptor { request.setAttribute(LoginService.LOGIN_IDENTITY_KEY, loginUser); } + // TODO 未解决单点登录问题 暂时直接放行 前面有网关的系统登录拦截 return true; // proceed with the next interceptor } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java index d640efffe..c3742bd75 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/dao/XxlJobInfoDao.java @@ -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 { public List pageList(@Param("offset") int offset, @Param("pagesize") int pagesize, @@ -46,4 +48,7 @@ public interface XxlJobInfoDao { public int scheduleUpdate(XxlJobInfo xxlJobInfo); + List 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); } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/LoginService.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/LoginService.java index 59134c2bf..afcff4447 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/LoginService.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/LoginService.java @@ -102,28 +102,5 @@ public class LoginService { } return null; } - /** - * cas登陆方法 - * - * @author hubg 2021-10-19 14:39:12 - */ - public ReturnT loginCas(HttpServletRequest request, HttpServletResponse response, String username) { - - // param - if (username == null || username.trim().length() == 0) { - return new ReturnT(500, I18nUtil.getString("login_param_empty")); - } - - XxlJobUser xxlJobUser = xxlJobUserDao.loadByUserName(username); - if (xxlJobUser == null) { - return new ReturnT(500, I18nUtil.getString("login_param_unvalid")); - } - - String loginToken = makeToken(xxlJobUser); - - // do login - CookieUtil.set(response, LOGIN_IDENTITY_KEY, loginToken, false); - return ReturnT.SUCCESS; - } } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/XxlJobService.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/XxlJobService.java index 60b4bb80d..d7c744075 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/XxlJobService.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/XxlJobService.java @@ -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> chartInfo(Date startDate, Date endDate); + /** + * api接口用于查找列表 + * @param pageNo + * @param pageSize + * @param name + * @param status + * @param handlerName + * @return + */ + PageResult apiPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName); } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index b7d968843..632285907 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -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>(result); } + @Override + public PageResult apiPage(Integer pageNo, Integer pageSize, String name, Integer status, String handlerName) { + PageResult 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; + } + } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/application.yaml b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/application.yaml index dff93b139..acf998377 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/application.yaml +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/application.yaml @@ -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 --- #################### 接口文档配置 #################### diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/bootstrap.yaml b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/bootstrap.yaml index 79517ff5c..184587608 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/bootstrap.yaml +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/bootstrap.yaml @@ -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: diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml index 7b3c3a3ed..059016897 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml @@ -228,6 +228,7 @@ LIMIT #{pagesize} + UPDATE xxl_job_info SET @@ -236,5 +237,46 @@ trigger_status = #{triggerStatus} WHERE id = #{id} + + + + + + + + + + + + \ No newline at end of file diff --git a/ludu-module-sampling/ludu-module-sampling-biz/pom.xml b/ludu-module-sampling/ludu-module-sampling-biz/pom.xml index 47bf92b7a..d2b88d27a 100644 --- a/ludu-module-sampling/ludu-module-sampling-biz/pom.xml +++ b/ludu-module-sampling/ludu-module-sampling-biz/pom.xml @@ -18,6 +18,11 @@ + + cn.iocoder.cloud + ludu-job-core + ${revision} + cn.iocoder.cloud @@ -128,11 +133,7 @@ cn.iocoder.cloud yudao-spring-boot-starter-monitor - - com.xuxueli - xxl-job-core - 2.3.1 - + diff --git a/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/service/SamplingJob.java b/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/service/SamplingJob.java new file mode 100644 index 000000000..5c5cf4817 --- /dev/null +++ b/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/service/SamplingJob.java @@ -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 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 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 + } +} diff --git a/ludu-module-sampling/ludu-module-sampling-biz/src/main/resources/application.yaml b/ludu-module-sampling/ludu-module-sampling-biz/src/main/resources/application.yaml index e74d8c678..9ff60a934 100644 --- a/ludu-module-sampling/ludu-module-sampling-biz/src/main/resources/application.yaml +++ b/ludu-module-sampling/ludu-module-sampling-biz/src/main/resources/application.yaml @@ -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 --- #################### 芋道相关配置 #################### diff --git a/ludu-module-ticket-manager/ludu-module-ticket-manager-api/src/main/java/cn/iocoder/yudao/module/ticket/api/asset/dto/TicketAssetRespDTO.java b/ludu-module-ticket-manager/ludu-module-ticket-manager-api/src/main/java/cn/iocoder/yudao/module/ticket/api/asset/dto/TicketAssetRespDTO.java index eb55f5ec1..190aa4465 100644 --- a/ludu-module-ticket-manager/ludu-module-ticket-manager-api/src/main/java/cn/iocoder/yudao/module/ticket/api/asset/dto/TicketAssetRespDTO.java +++ b/ludu-module-ticket-manager/ludu-module-ticket-manager-api/src/main/java/cn/iocoder/yudao/module/ticket/api/asset/dto/TicketAssetRespDTO.java @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; /** - * @Description TODO + * @Description 设备管理 */ @Schema(description = "RPC 服务 - 设备管理 Response DTO") @Data diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java index 90822de9d..f40a230f9 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java @@ -124,28 +124,31 @@ public class YudaoWebSecurityConfigurerAdapter { // 获得 @PermitAll 带来的 URL 列表,免登录 Multimap 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); diff --git a/yudao-module-infra/yudao-module-infra-biz/pom.xml b/yudao-module-infra/yudao-module-infra-biz/pom.xml index 91e1386de..77b5e7900 100644 --- a/yudao-module-infra/yudao-module-infra-biz/pom.xml +++ b/yudao-module-infra/yudao-module-infra-biz/pom.xml @@ -19,6 +19,11 @@ + + cn.iocoder.cloud + ludu-job-admin-api + ${revision} + org.springframework.cloud @@ -92,6 +97,11 @@ cn.iocoder.cloud yudao-spring-boot-starter-job + + cn.iocoder.cloud + ludu-job-core + ${revision} + diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java index c48c7c2f0..10d3b6ad3 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java @@ -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 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 getJobPage() { - return null; + public CommonResult> 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); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/rpc/config/RpcConfiguration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/rpc/config/RpcConfiguration.java index f0ac5a6cc..3eed0ed76 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/rpc/config/RpcConfiguration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/rpc/config/RpcConfiguration.java @@ -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 { } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml index 16377da0c..a9eab01fa 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml @@ -89,7 +89,7 @@ spring: --- #################### 定时任务相关配置 #################### xxl: job: - enabled: true # 是否开启调度中心,默认为 true 开启 + enabled: false # 是否开启调度中心,默认为 true 开启 admin: addresses: http://127.0.0.1:9090/xxl-job-admin # 调度中心部署跟地址