This commit is contained in:
王奎兴
2026-08-26 14:08:24 +08:00
parent f2f3fb9c19
commit 02a0b7aab6
7 changed files with 186 additions and 1 deletions
@@ -0,0 +1,23 @@
package com.mhd.system.api;
import com.mhd.common.core.constant.ServiceNameConstants;
import com.mhd.common.core.domain.entity.R;
import com.mhd.common.core.domain.dto.YmsSysUserDTO;
import com.mhd.system.api.domain.YmsLoginUser;
import com.mhd.system.api.factory.RemoteBmsFeignFallbackFactory;
import com.mhd.system.api.factory.RemoteXxlJobFeignFallbackFactory;
import com.mhd.system.api.feign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@FeignClient(contextId = "XxlJobService", value = ServiceNameConstants.XXL_JOB_SERVICE,url = "http://127.0.0.1:8020",fallbackFactory = RemoteXxlJobFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface XxlJobServiceFeign {
@GetMapping("/user/openFeignTest")
public R<Map<String, Object>> openFeignTest(@RequestParam("param") String string);
}
@@ -0,0 +1,44 @@
package com.mhd.system.api.factory;
import com.mhd.common.core.domain.dto.BusinessDataPushDTO;
import com.mhd.common.core.domain.entity.R;
import com.mhd.common.core.domain.po.OrganizationPo;
import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.system.api.BmsServiceFeign;
import com.mhd.system.api.ProductServiceFeign;
import com.mhd.system.api.XxlJobServiceFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @Description
* @Author zg
* @Version 1.0
* @Date 2023/11/3 14:37
*/
@Component
public class RemoteXxlJobFeignFallbackFactory implements FallbackFactory<XxlJobServiceFeign> {
private static final Logger log = LoggerFactory.getLogger(RemoteXxlJobFeignFallbackFactory.class);
@Override
public XxlJobServiceFeign create(Throwable throwable) {
log.error("系统服务调用失败:{}", throwable.getMessage());
return new XxlJobServiceFeign() {
@Override
public R<Map<String, Object>> openFeignTest(String string) {
return null;
}
};
}
}
@@ -66,6 +66,9 @@ public class ServiceNameConstants
//YMS系统
public static final String YMS_SERVICE = "mhd-yms-service";
//YMS系统
public static final String XXL_JOB_SERVICE = "xxl-job-service";
}
+5
View File
@@ -80,6 +80,11 @@
<artifactId>opencc4j</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.4.0</version>
</dependency>
<!-- Mhd Common Log -->
<dependency>
<groupId>com.mhd</groupId>
@@ -1,11 +1,13 @@
package com.mhd.wms.interfaces.facadeApi.stockInOrder;
import com.mhd.common.core.domain.entity.R;
import com.mhd.common.core.web.controller.BaseController;
import com.mhd.common.core.utils.bean.BeanUtils;
import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.core.web.page.TableDataInfo;
import com.mhd.common.core.exception.ServiceException;
import com.mhd.common.core.utils.StringUtils;
import com.mhd.system.api.XxlJobServiceFeign;
import com.mhd.wms.application.service.stockInOrder.StockInOrderApplicationService;
import com.mhd.wms.domain.inMaterialDetail.entity.InMaterialDetail;
import com.mhd.wms.domain.inMaterialDetail.repository.po.InMaterialDetailPO;
@@ -20,6 +22,8 @@ import com.mhd.wms.interfaces.assember.stockOutOrder.StockOutOrderAssembler;
import com.mhd.wms.interfaces.dto.inMaterialDetail.InMaterialDetailDTO;
import com.mhd.wms.interfaces.dto.stockInOrder.StockInOrderDTO;
import com.mhd.wms.interfaces.dto.stockOutOrder.StockOutOrderDTO;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -49,6 +53,8 @@ public class StockInOrderApi extends BaseController {
private StockInOrderAssembler stockInOrderAssembler;
@Resource
private StockOutOrderAssembler stockOutOrderAssembler;
@Autowired
private XxlJobServiceFeign xxlJobServiceFeign;
/**
* 分页查询入库单列表
@@ -347,4 +353,32 @@ public class StockInOrderApi extends BaseController {
return stockInOrderApplicationService.batchSignature(dto);
}
@GetMapping("/xxlopenfeign")
public AjaxResult xxlopenfeign(@RequestParam String param) {
R<Map<String, Object>> mapR = xxlJobServiceFeign.openFeignTest(param);
return AjaxResult.success(mapR);
}
/**
* 1. 简单任务示例(Bean模式)
* 这里的 demoJobHandler 必须和调度中心配置一致
*/
@XxlJob("demoJobHandler")
public void demoJobHandler() {
// 获取任务参数
String param = XxlJobHelper.getJobParam();
logger.info("XXL-JOB 开始执行,参数:{}", param);
try {
// ========== 你的业务逻辑 ==========
logger.info("执行若依微服务定时任务...");
// 设置任务执行结果
XxlJobHelper.handleSuccess("执行成功");
} catch (Exception e) {
logger.error("XXL-JOB 执行失败", e);
XxlJobHelper.handleFail("执行失败:" + e.getMessage());
}
}
}
@@ -0,0 +1,54 @@
package com.mhd.wms.util;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* XXL-JOB 配置类
*/
@Configuration
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address}")
private String address;
@Value("${xxl.job.executor.ip}")
private String ip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
+23 -1
View File
@@ -34,4 +34,26 @@ spring:
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# XXL-JOB 配置
xxl:
job:
# 调度中心地址(填你部署的地址)
admin:
addresses: http://192.168.1.6:8020/xxl-job-admin
# 执行器配置
executor:
# 执行器名称(自定义,后面调度中心要用到)
appname: wms-service-executor
# 执行器注册地址,默认0表示自动获取
address:
# 执行器IP,默认空自动获取
ip:
# 执行器端口号(每个微服务不能重复,建议9997/9998/9999
port: 9997
# 执行器日志存放路径
logpath: /data/applogs/xxl-job/jobhandler
# 日志保留天数
logretentiondays: 30
# 调度中心通讯令牌(默认空,安全可设置)
accessToken: default_token