Merge remote-tracking branch 'origin/boot3.0' into boot3.0
# Conflicts: # init-file/cloud-quartz.sql # init-file/cloud-seata.sql # init-file/cloud-system.sql # init-file/nacos_config.zipdetached
commit
3b09796958
|
@ -52,6 +52,12 @@
|
||||||
<artifactId>cloud-common-security</artifactId>
|
<artifactId>cloud-common-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 接口模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
cloud-common-swagger系统接口
|
cloud-common-api-doc系统接口
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -23,22 +23,10 @@
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger -->
|
<!-- knife4j-openapi3 -->
|
||||||
<!--<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||||
<version>2.5.0</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.common.api.doc.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SpringDocConfig {
|
||||||
|
|
||||||
|
@Value("${spring.application.name}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
private Info info(){
|
||||||
|
return new Info()
|
||||||
|
.title(String.format("%S-微服务接口文档", applicationName))
|
||||||
|
.description("微服务接口文档,根据此接口文档可以进行前后端功能对接/联调")
|
||||||
|
.version("v1.0.0");
|
||||||
|
}
|
||||||
|
private ExternalDocumentation externalDocumentation() {
|
||||||
|
return new ExternalDocumentation()
|
||||||
|
.description("服务总站")
|
||||||
|
.url("https://gitea.qinmian.online");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI springShopOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(info())
|
||||||
|
.externalDocs(externalDocumentation());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.common.api.doc.config.SpringDocConfig
|
|
@ -142,12 +142,6 @@
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.swagger</groupId>
|
|
||||||
<artifactId>swagger-annotations</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- lombok -->
|
<!-- lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.muyu.common.swagger.annotation;
|
|
||||||
|
|
||||||
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
@Target({ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
@Inherited
|
|
||||||
@Import({SwaggerAutoConfiguration.class})
|
|
||||||
public @interface EnableCustomSwagger2 {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
package com.muyu.common.swagger.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.*;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
||||||
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
|
||||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
|
||||||
@Import({SwaggerBeanPostProcessor.class, SwaggerWebConfiguration.class})
|
|
||||||
public class SwaggerAutoConfiguration {
|
|
||||||
/**
|
|
||||||
* 默认的排除路径,排除Spring Boot默认的错误处理路径和端点
|
|
||||||
*/
|
|
||||||
private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");
|
|
||||||
|
|
||||||
private static final String BASE_PATH = "/**";
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket api (SwaggerProperties swaggerProperties) {
|
|
||||||
// base-path处理
|
|
||||||
if (swaggerProperties.getBasePath().isEmpty()) {
|
|
||||||
swaggerProperties.getBasePath().add(BASE_PATH);
|
|
||||||
}
|
|
||||||
// noinspection unchecked
|
|
||||||
List<Predicate<String>> basePath = new ArrayList<Predicate<String>>();
|
|
||||||
swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
|
|
||||||
|
|
||||||
// exclude-path处理
|
|
||||||
if (swaggerProperties.getExcludePath().isEmpty()) {
|
|
||||||
swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Predicate<String>> excludePath = new ArrayList<>();
|
|
||||||
swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));
|
|
||||||
|
|
||||||
ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
|
|
||||||
.apiInfo(apiInfo(swaggerProperties)).select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));
|
|
||||||
|
|
||||||
swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));
|
|
||||||
swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));
|
|
||||||
|
|
||||||
return builder.build().securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 安全模式,这里指定token通过Authorization头请求头传递
|
|
||||||
*/
|
|
||||||
private List<SecurityScheme> securitySchemes () {
|
|
||||||
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
|
||||||
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
|
||||||
return apiKeyList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 安全上下文
|
|
||||||
*/
|
|
||||||
private List<SecurityContext> securityContexts () {
|
|
||||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
|
||||||
securityContexts.add(
|
|
||||||
SecurityContext.builder()
|
|
||||||
.securityReferences(defaultAuth())
|
|
||||||
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
|
||||||
.build());
|
|
||||||
return securityContexts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认的全局鉴权策略
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<SecurityReference> defaultAuth () {
|
|
||||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
|
||||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
|
||||||
authorizationScopes[0] = authorizationScope;
|
|
||||||
List<SecurityReference> securityReferences = new ArrayList<>();
|
|
||||||
securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
|
||||||
return securityReferences;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo (SwaggerProperties swaggerProperties) {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title(swaggerProperties.getTitle())
|
|
||||||
.description(swaggerProperties.getDescription())
|
|
||||||
.license(swaggerProperties.getLicense())
|
|
||||||
.licenseUrl(swaggerProperties.getLicenseUrl())
|
|
||||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
|
||||||
.contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail()))
|
|
||||||
.version(swaggerProperties.getVersion())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.muyu.common.swagger.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
|
||||||
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
|
||||||
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger 在 springboot 2.6.x 不兼容问题的处理
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class SwaggerBeanPostProcessor implements BeanPostProcessor {
|
|
||||||
@Override
|
|
||||||
public Object postProcessAfterInitialization (Object bean, String beanName) throws BeansException {
|
|
||||||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
|
||||||
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
|
|
||||||
}
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings (List<T> mappings) {
|
|
||||||
List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
mappings.clear();
|
|
||||||
mappings.addAll(copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<RequestMappingInfoHandlerMapping> getHandlerMappings (Object bean) {
|
|
||||||
try {
|
|
||||||
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
|
||||||
field.setAccessible(true);
|
|
||||||
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,296 +0,0 @@
|
||||||
package com.muyu.common.swagger.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ConfigurationProperties("swagger")
|
|
||||||
public class SwaggerProperties {
|
|
||||||
/**
|
|
||||||
* 是否开启swagger
|
|
||||||
*/
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger会解析的包路径
|
|
||||||
**/
|
|
||||||
private String basePackage = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger会解析的url规则
|
|
||||||
**/
|
|
||||||
private List<String> basePath = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在basePath基础上需要排除的url规则
|
|
||||||
**/
|
|
||||||
private List<String> excludePath = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
**/
|
|
||||||
private String title = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述
|
|
||||||
**/
|
|
||||||
private String description = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
**/
|
|
||||||
private String version = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 许可证
|
|
||||||
**/
|
|
||||||
private String license = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 许可证URL
|
|
||||||
**/
|
|
||||||
private String licenseUrl = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务条款URL
|
|
||||||
**/
|
|
||||||
private String termsOfServiceUrl = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* host信息
|
|
||||||
**/
|
|
||||||
private String host = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系人信息
|
|
||||||
*/
|
|
||||||
private Contact contact = new Contact();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局统一鉴权配置
|
|
||||||
**/
|
|
||||||
private Authorization authorization = new Authorization();
|
|
||||||
|
|
||||||
public Boolean getEnabled () {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled (Boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBasePackage () {
|
|
||||||
return basePackage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasePackage (String basePackage) {
|
|
||||||
this.basePackage = basePackage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getBasePath () {
|
|
||||||
return basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasePath (List<String> basePath) {
|
|
||||||
this.basePath = basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getExcludePath () {
|
|
||||||
return excludePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExcludePath (List<String> excludePath) {
|
|
||||||
this.excludePath = excludePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle () {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle (String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription () {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription (String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion () {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion (String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLicense () {
|
|
||||||
return license;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLicense (String license) {
|
|
||||||
this.license = license;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLicenseUrl () {
|
|
||||||
return licenseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLicenseUrl (String licenseUrl) {
|
|
||||||
this.licenseUrl = licenseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTermsOfServiceUrl () {
|
|
||||||
return termsOfServiceUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTermsOfServiceUrl (String termsOfServiceUrl) {
|
|
||||||
this.termsOfServiceUrl = termsOfServiceUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHost () {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost (String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contact getContact () {
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContact (Contact contact) {
|
|
||||||
this.contact = contact;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Authorization getAuthorization () {
|
|
||||||
return authorization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorization (Authorization authorization) {
|
|
||||||
this.authorization = authorization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Contact {
|
|
||||||
/**
|
|
||||||
* 联系人
|
|
||||||
**/
|
|
||||||
private String name = "";
|
|
||||||
/**
|
|
||||||
* 联系人url
|
|
||||||
**/
|
|
||||||
private String url = "";
|
|
||||||
/**
|
|
||||||
* 联系人email
|
|
||||||
**/
|
|
||||||
private String email = "";
|
|
||||||
|
|
||||||
public String getName () {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName (String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl () {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl (String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail () {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail (String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Authorization {
|
|
||||||
/**
|
|
||||||
* 鉴权策略ID,需要和SecurityReferences ID保持一致
|
|
||||||
*/
|
|
||||||
private String name = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 需要开启鉴权URL的正则
|
|
||||||
*/
|
|
||||||
private String authRegex = "^.*$";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 鉴权作用域列表
|
|
||||||
*/
|
|
||||||
private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
|
||||||
|
|
||||||
private List<String> tokenUrlList = new ArrayList<>();
|
|
||||||
|
|
||||||
public String getName () {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName (String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthRegex () {
|
|
||||||
return authRegex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthRegex (String authRegex) {
|
|
||||||
this.authRegex = authRegex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<AuthorizationScope> getAuthorizationScopeList () {
|
|
||||||
return authorizationScopeList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorizationScopeList (List<AuthorizationScope> authorizationScopeList) {
|
|
||||||
this.authorizationScopeList = authorizationScopeList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getTokenUrlList () {
|
|
||||||
return tokenUrlList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTokenUrlList (List<String> tokenUrlList) {
|
|
||||||
this.tokenUrlList = tokenUrlList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class AuthorizationScope {
|
|
||||||
/**
|
|
||||||
* 作用域名称
|
|
||||||
*/
|
|
||||||
private String scope = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 作用域描述
|
|
||||||
*/
|
|
||||||
private String description = "";
|
|
||||||
|
|
||||||
public String getScope () {
|
|
||||||
return scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScope (String scope) {
|
|
||||||
this.scope = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription () {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription (String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package com.muyu.common.swagger.config;
|
|
||||||
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger 资源映射路径
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class SwaggerWebConfiguration implements WebMvcConfigurer {
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers (ResourceHandlerRegistry registry) {
|
|
||||||
/** swagger-ui 地址 */
|
|
||||||
registry.addResourceHandler("/swagger-ui/**")
|
|
||||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
# com.muyu.common.swagger.config.SwaggerAutoConfiguration
|
|
||||||
# com.muyu.common.swagger.config.SwaggerWebConfiguration
|
|
||||||
# com.muyu.common.swagger.config.SwaggerBeanPostProcessor
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
|
|
||||||
|
<description>XllJob定时任务</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- MuYu Common Core-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- xxl-job-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.common.xxl;
|
||||||
|
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class XXLJobConfig {
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties) {
|
||||||
|
if (StringUtils.isEmpty(xxlJobProperties.getAdminAddresses())){
|
||||||
|
throw new RuntimeException("请在bootstrap.yml当中配置shared-configs项,xxl-job共享配置[application-xxl-config]");
|
||||||
|
}
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
|
||||||
|
xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppName());
|
||||||
|
xxlJobSpringExecutor.setIp(xxlJobProperties.getIp());
|
||||||
|
xxlJobSpringExecutor.setPort(xxlJobProperties.getPort());
|
||||||
|
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
|
||||||
|
xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath());
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
|
||||||
|
log.info(">>>>>>>>>>> xxl-job config init success.");
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.muyu.common.xxl;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "xxl-job")
|
||||||
|
public class XxlJobProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调度中心部署根地址 [选填]:
|
||||||
|
* 如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";
|
||||||
|
* 为空则关闭自动注册;
|
||||||
|
*/
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器通讯TOKEN [选填]:
|
||||||
|
* 非空时启用;
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器AppName [选填]:
|
||||||
|
* 执行器心跳注册分组依据;为空则关闭自动注册
|
||||||
|
*/
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器注册 [选填]:
|
||||||
|
* 优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。
|
||||||
|
* 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
|
||||||
|
*/
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器IP [选填]:
|
||||||
|
* 默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;
|
||||||
|
* 地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器端口号 [选填]:
|
||||||
|
* 小于等于0则自动获取;默认端口为9999,
|
||||||
|
* 单机部署多个执行器时,注意要配置不同执行器端口;
|
||||||
|
*/
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器运行日志文件存储磁盘路径 [选填]:
|
||||||
|
* 需要对该路径拥有读写权限;为空则使用默认路径;
|
||||||
|
*/
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器日志文件保存天数 [选填]:
|
||||||
|
* 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
|
||||||
|
*/
|
||||||
|
private int logRetentionDays;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.common.xxl.demo;
|
||||||
|
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class XxlJobDemoService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参测试
|
||||||
|
*/
|
||||||
|
@XxlJob("xxl-job-demo-no-param")
|
||||||
|
public void xxlJobDemoNoParam(){
|
||||||
|
log.info("调度名称:[{}] - 无参", "xxl-job-demo-no-param");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有参测试
|
||||||
|
*/
|
||||||
|
@XxlJob("xxl-job-demo-one-param")
|
||||||
|
public void xxlJobDemoOneParam(){
|
||||||
|
String param = XxlJobHelper.getJobParam();
|
||||||
|
log.info("调度名称:[{}] - 参数:[{}]", "xxl-job-demo-one-param", param);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
com.muyu.common.xxl.XXLJobConfig
|
||||||
|
com.muyu.common.xxl.XxlJobProperties
|
||||||
|
com.muyu.common.xxl.demo.XxlJobDemoService
|
|
@ -13,11 +13,12 @@
|
||||||
<module>cloud-common-core</module>
|
<module>cloud-common-core</module>
|
||||||
<module>cloud-common-redis</module>
|
<module>cloud-common-redis</module>
|
||||||
<module>cloud-common-seata</module>
|
<module>cloud-common-seata</module>
|
||||||
<module>cloud-common-swagger</module>
|
<module>cloud-common-api-doc</module>
|
||||||
<module>cloud-common-security</module>
|
<module>cloud-common-security</module>
|
||||||
<module>cloud-common-datascope</module>
|
<module>cloud-common-datascope</module>
|
||||||
<module>cloud-common-datasource</module>
|
<module>cloud-common-datasource</module>
|
||||||
<module>cloud-common-system</module>
|
<module>cloud-common-system</module>
|
||||||
|
<module>cloud-common-xxl</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
|
|
@ -76,16 +76,10 @@
|
||||||
<artifactId>cloud-common-redis</artifactId>
|
<artifactId>cloud-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
||||||
<version>${swagger.fox.version}</version>
|
<version>4.5.0</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
package com.muyu.gateway.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
|
||||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
|
||||||
import org.springframework.cloud.gateway.support.NameUtils;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
|
||||||
import springfox.documentation.swagger.web.SwaggerResource;
|
|
||||||
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 聚合系统接口
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer {
|
|
||||||
/**
|
|
||||||
* Swagger2默认的url后缀
|
|
||||||
*/
|
|
||||||
public static final String SWAGGER2URL = "/v2/api-docs";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 网关路由
|
|
||||||
*/
|
|
||||||
@Lazy
|
|
||||||
@Autowired
|
|
||||||
private RouteLocator routeLocator;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GatewayProperties gatewayProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 聚合其他服务接口
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<SwaggerResource> get () {
|
|
||||||
List<SwaggerResource> resourceList = new ArrayList<>();
|
|
||||||
List<String> routes = new ArrayList<>();
|
|
||||||
// 获取网关中配置的route
|
|
||||||
routeLocator.getRoutes().subscribe(route -> routes.add(route.getId()));
|
|
||||||
gatewayProperties.getRoutes().stream()
|
|
||||||
.filter(routeDefinition -> routes
|
|
||||||
.contains(routeDefinition.getId()))
|
|
||||||
.forEach(routeDefinition -> routeDefinition.getPredicates().stream()
|
|
||||||
.filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName()))
|
|
||||||
.filter(predicateDefinition -> !"cloud-auth".equalsIgnoreCase(routeDefinition.getId()))
|
|
||||||
.forEach(predicateDefinition -> resourceList
|
|
||||||
.add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs()
|
|
||||||
.get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", SWAGGER2URL)))));
|
|
||||||
return resourceList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SwaggerResource swaggerResource (String name, String location) {
|
|
||||||
SwaggerResource swaggerResource = new SwaggerResource();
|
|
||||||
swaggerResource.setName(name);
|
|
||||||
swaggerResource.setLocation(location);
|
|
||||||
swaggerResource.setSwaggerVersion("2.0");
|
|
||||||
return swaggerResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers (ResourceHandlerRegistry registry) {
|
|
||||||
/** swagger-ui 地址 */
|
|
||||||
registry.addResourceHandler("/swagger-ui/**")
|
|
||||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.muyu.gateway.filter.log;
|
package com.muyu.gateway.filter;
|
||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
import com.muyu.common.core.constant.SecurityConstants;
|
||||||
|
import com.muyu.gateway.model.AccessLog;
|
||||||
import com.muyu.gateway.utils.WebFrameworkUtils;
|
import com.muyu.gateway.utils.WebFrameworkUtils;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
|
@ -1,46 +0,0 @@
|
||||||
package com.muyu.gateway.handler;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import springfox.documentation.swagger.web.*;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/swagger-resources")
|
|
||||||
public class SwaggerHandler {
|
|
||||||
private final SwaggerResourcesProvider swaggerResources;
|
|
||||||
@Autowired(required = false)
|
|
||||||
private SecurityConfiguration securityConfiguration;
|
|
||||||
@Autowired(required = false)
|
|
||||||
private UiConfiguration uiConfiguration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SwaggerHandler (SwaggerResourcesProvider swaggerResources) {
|
|
||||||
this.swaggerResources = swaggerResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/configuration/security")
|
|
||||||
public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration () {
|
|
||||||
return Mono.just(new ResponseEntity<>(
|
|
||||||
Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()),
|
|
||||||
HttpStatus.OK));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/configuration/ui")
|
|
||||||
public Mono<ResponseEntity<UiConfiguration>> uiConfiguration () {
|
|
||||||
return Mono.just(new ResponseEntity<>(
|
|
||||||
Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@GetMapping("")
|
|
||||||
public Mono<ResponseEntity> swaggerResources () {
|
|
||||||
return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK)));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.gateway.filter.log;
|
package com.muyu.gateway.model;
|
||||||
|
|
||||||
import com.alibaba.cloud.commons.io.StringBuilderWriter;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -9,7 +8,6 @@ import lombok.NoArgsConstructor;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import org.springframework.cloud.gateway.route.Route;
|
import org.springframework.cloud.gateway.route.Route;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.HttpStatusCode;
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
@ -61,3 +61,15 @@ spring:
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
data-type: json
|
data-type: json
|
||||||
rule-type: gw-flow
|
rule-type: gw-flow
|
||||||
|
knife4j:
|
||||||
|
gateway:
|
||||||
|
enabled: true
|
||||||
|
# 指定服务发现的模式聚合微服务文档,并且是默认`default`分组
|
||||||
|
strategy: discover
|
||||||
|
discover:
|
||||||
|
enabled: true
|
||||||
|
# 指定版本号(Swagger2|OpenAPI3)
|
||||||
|
version : openapi3
|
||||||
|
# 需要排除的微服务(eg:网关服务)
|
||||||
|
excluded-services:
|
||||||
|
- cloud-monitor
|
||||||
|
|
|
@ -48,22 +48,16 @@
|
||||||
<version>${minio.version}</version>
|
<version>${minio.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- MuYu Common Swagger -->
|
|
||||||
<!--<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
|
||||||
</dependency>
|
|
||||||
-->
|
|
||||||
<!-- MuYu Common System-->
|
<!-- MuYu Common System-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-system</artifactId>
|
<artifactId>cloud-common-system</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 接口模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
|
|
@ -41,13 +41,6 @@
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger UI -->
|
|
||||||
<!--<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>-->
|
|
||||||
|
|
||||||
<!-- Apache Velocity -->
|
<!-- Apache Velocity -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.velocity</groupId>
|
<groupId>org.apache.velocity</groupId>
|
||||||
|
@ -66,15 +59,16 @@
|
||||||
<artifactId>cloud-common-log</artifactId>
|
<artifactId>cloud-common-log</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- MuYu Common Swagger -->
|
<!-- 接口模块 -->
|
||||||
<!--<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
|
||||||
</dependency>-->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- XllJob定时任务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.gen;
|
||||||
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
//import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@ -12,7 +11,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
//@EnableCustomSwagger2
|
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class CloudGenApplication {
|
public class CloudGenApplication {
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
@ -47,3 +47,5 @@ spring:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
# 系统环境Config共享配置
|
# 系统环境Config共享配置
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# xxl-job 配置文件
|
||||||
|
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
|
@ -1,105 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-modules</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>cloud-modules-job</artifactId>
|
|
||||||
|
|
||||||
<description>
|
|
||||||
cloud-modules-job定时任务
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos Config -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Sentinel -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringBoot Actuator -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Swagger UI -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Quartz -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.quartz-scheduler</groupId>
|
|
||||||
<artifactId>quartz</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.mchange</groupId>
|
|
||||||
<artifactId>c3p0</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Log -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-log</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Swagger -->
|
|
||||||
<!--<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
|
||||||
</dependency>-->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<finalName>${project.artifactId}</finalName>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,22 +0,0 @@
|
||||||
package com.muyu.job;
|
|
||||||
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|
||||||
//import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@EnableCustomConfig
|
|
||||||
//@EnableCustomSwagger2
|
|
||||||
@EnableMyFeignClients
|
|
||||||
@SpringBootApplication
|
|
||||||
public class CloudJobApplication {
|
|
||||||
public static void main (String[] args) {
|
|
||||||
SpringApplication.run(CloudJobApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
//package com.muyu.job.config;
|
|
||||||
//
|
|
||||||
//import java.util.Properties;
|
|
||||||
//import javax.sql.DataSource;
|
|
||||||
//import org.springframework.context.annotation.Bean;
|
|
||||||
//import org.springframework.context.annotation.Configuration;
|
|
||||||
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 定时任务配置(单机部署建议删除此类和qrtz数据库表,默认走内存会最高效)
|
|
||||||
// *
|
|
||||||
// * @author muyu
|
|
||||||
// */
|
|
||||||
//@Configuration
|
|
||||||
//public class ScheduleConfig
|
|
||||||
//{
|
|
||||||
// @Bean
|
|
||||||
// public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
|
|
||||||
// {
|
|
||||||
// SchedulerFactoryBean factory = new SchedulerFactoryBean();
|
|
||||||
// factory.setDataSource(dataSource);
|
|
||||||
//
|
|
||||||
// // quartz参数
|
|
||||||
// Properties prop = new Properties();
|
|
||||||
// prop.put("org.quartz.scheduler.instanceName", "MuYuScheduler");
|
|
||||||
// prop.put("org.quartz.scheduler.instanceId", "AUTO");
|
|
||||||
// // 线程池配置
|
|
||||||
// prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
|
|
||||||
// prop.put("org.quartz.threadPool.threadCount", "20");
|
|
||||||
// prop.put("org.quartz.threadPool.threadPriority", "5");
|
|
||||||
// // JobStore配置
|
|
||||||
// prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
|
|
||||||
// // 集群配置
|
|
||||||
// prop.put("org.quartz.jobStore.isClustered", "true");
|
|
||||||
// prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
|
|
||||||
// prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
|
|
||||||
// prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
|
|
||||||
//
|
|
||||||
// // sqlserver 启用
|
|
||||||
// // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
|
|
||||||
// prop.put("org.quartz.jobStore.misfireThreshold", "12000");
|
|
||||||
// prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
|
|
||||||
// factory.setQuartzProperties(prop);
|
|
||||||
//
|
|
||||||
// factory.setSchedulerName("MuYuScheduler");
|
|
||||||
// // 延时启动
|
|
||||||
// factory.setStartupDelay(1);
|
|
||||||
// factory.setApplicationContextSchedulerContextKey("applicationContextKey");
|
|
||||||
// // 可选,QuartzScheduler
|
|
||||||
// // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
|
|
||||||
// factory.setOverwriteExistingJobs(true);
|
|
||||||
// // 设置自动启动,默认为true
|
|
||||||
// factory.setAutoStartup(true);
|
|
||||||
//
|
|
||||||
// return factory;
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -1,149 +0,0 @@
|
||||||
package com.muyu.job.controller;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.Constants;
|
|
||||||
import com.muyu.common.core.exception.job.TaskException;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
|
||||||
import com.muyu.common.log.annotation.Log;
|
|
||||||
import com.muyu.common.log.enums.BusinessType;
|
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import com.muyu.job.service.ISysJobService;
|
|
||||||
import com.muyu.job.util.CronUtils;
|
|
||||||
import com.muyu.job.util.ScheduleUtils;
|
|
||||||
import org.quartz.SchedulerException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度任务信息操作处理
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/job")
|
|
||||||
public class SysJobController extends BaseController {
|
|
||||||
@Autowired
|
|
||||||
private ISysJobService jobService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询定时任务列表
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:list")
|
|
||||||
@GetMapping("/list")
|
|
||||||
public Result<TableDataInfo<SysJob>> list (SysJob sysJob) {
|
|
||||||
startPage();
|
|
||||||
List<SysJob> list = jobService.selectJobList(sysJob);
|
|
||||||
return getDataTable(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出定时任务列表
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:export")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.EXPORT)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export (HttpServletResponse response, SysJob sysJob) {
|
|
||||||
List<SysJob> list = jobService.selectJobList(sysJob);
|
|
||||||
ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
|
|
||||||
util.exportExcel(response, list, "定时任务");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取定时任务详细信息
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:query")
|
|
||||||
@GetMapping(value = "/{jobId}")
|
|
||||||
public Result getInfo (@PathVariable("jobId") Long jobId) {
|
|
||||||
return success(jobService.selectJobById(jobId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增定时任务
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:add")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.INSERT)
|
|
||||||
@PostMapping
|
|
||||||
public Result add (@RequestBody SysJob job) throws SchedulerException, TaskException {
|
|
||||||
if (!CronUtils.isValid(job.getCronExpression())) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
|
||||||
} else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS})) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.HTTP, Constants.HTTPS})) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
|
||||||
} else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) {
|
|
||||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
|
||||||
}
|
|
||||||
job.setCreateBy(SecurityUtils.getUsername());
|
|
||||||
return toAjax(jobService.insertJob(job));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改定时任务
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:edit")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
|
||||||
@PutMapping
|
|
||||||
public Result edit (@RequestBody SysJob job) throws SchedulerException, TaskException {
|
|
||||||
if (!CronUtils.isValid(job.getCronExpression())) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
|
||||||
} else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS})) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{Constants.HTTP, Constants.HTTPS})) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
|
||||||
} else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
|
||||||
} else if (!ScheduleUtils.whiteList(job.getInvokeTarget())) {
|
|
||||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
|
||||||
}
|
|
||||||
job.setUpdateBy(SecurityUtils.getUsername());
|
|
||||||
return toAjax(jobService.updateJob(job));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务状态修改
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:changeStatus")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
|
||||||
@PutMapping("/changeStatus")
|
|
||||||
public Result changeStatus (@RequestBody SysJob job) throws SchedulerException {
|
|
||||||
SysJob newJob = jobService.selectJobById(job.getJobId());
|
|
||||||
newJob.setStatus(job.getStatus());
|
|
||||||
return toAjax(jobService.changeStatus(newJob));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务立即执行一次
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:changeStatus")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
|
||||||
@PutMapping("/run")
|
|
||||||
public Result run (@RequestBody SysJob job) throws SchedulerException {
|
|
||||||
boolean result = jobService.run(job);
|
|
||||||
return result ? success() : error("任务不存在或已过期!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除定时任务
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:remove")
|
|
||||||
@Log(title = "定时任务", businessType = BusinessType.DELETE)
|
|
||||||
@DeleteMapping("/{jobIds}")
|
|
||||||
public Result remove (@PathVariable("jobIds") Long[] jobIds) throws SchedulerException, TaskException {
|
|
||||||
jobService.deleteJobByIds(jobIds);
|
|
||||||
return success();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
package com.muyu.job.controller;
|
|
||||||
|
|
||||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
|
||||||
import com.muyu.common.log.annotation.Log;
|
|
||||||
import com.muyu.common.log.enums.BusinessType;
|
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
|
||||||
import com.muyu.job.domain.SysJobLog;
|
|
||||||
import com.muyu.job.service.ISysJobLogService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度日志操作处理
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/job/log")
|
|
||||||
public class SysJobLogController extends BaseController {
|
|
||||||
@Autowired
|
|
||||||
private ISysJobLogService jobLogService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询定时任务调度日志列表
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:list")
|
|
||||||
@GetMapping("/list")
|
|
||||||
public Result<TableDataInfo<SysJobLog>> list (SysJobLog sysJobLog) {
|
|
||||||
startPage();
|
|
||||||
List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
|
||||||
return getDataTable(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出定时任务调度日志列表
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:export")
|
|
||||||
@Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export (HttpServletResponse response, SysJobLog sysJobLog) {
|
|
||||||
List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
|
||||||
ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
|
|
||||||
util.exportExcel(response, list, "调度日志");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据调度编号获取详细信息
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:query")
|
|
||||||
@GetMapping(value = "/{jobLogId}")
|
|
||||||
public Result getInfo (@PathVariable("jobLogId") Long jobLogId) {
|
|
||||||
return success(jobLogService.selectJobLogById(jobLogId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除定时任务调度日志
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:remove")
|
|
||||||
@Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
|
|
||||||
@DeleteMapping("/{jobLogIds}")
|
|
||||||
public Result remove (@PathVariable("jobLogIds") Long[] jobLogIds) {
|
|
||||||
return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空定时任务调度日志
|
|
||||||
*/
|
|
||||||
@RequiresPermissions("monitor:job:remove")
|
|
||||||
@Log(title = "调度日志", businessType = BusinessType.CLEAN)
|
|
||||||
@DeleteMapping("/clean")
|
|
||||||
public Result clean () {
|
|
||||||
jobLogService.cleanJobLog();
|
|
||||||
return success();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
package com.muyu.job.domain;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import com.muyu.common.core.annotation.Excel.ColumnType;
|
|
||||||
import com.muyu.common.core.constant.ScheduleConstants;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
|
||||||
import com.muyu.job.util.CronUtils;
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度表 sys_job
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@SuperBuilder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class SysJob extends BaseEntity {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务ID
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务序号", cellType = ColumnType.NUMERIC)
|
|
||||||
private Long jobId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务名称
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务名称")
|
|
||||||
private String jobName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务组名
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务组名")
|
|
||||||
private String jobGroup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用目标字符串
|
|
||||||
*/
|
|
||||||
@Excel(name = "调用目标字符串")
|
|
||||||
private String invokeTarget;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cron执行表达式
|
|
||||||
*/
|
|
||||||
@Excel(name = "执行表达式 ")
|
|
||||||
private String cronExpression;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cron计划策略
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
@Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")
|
|
||||||
private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否并发执行(0允许 1禁止)
|
|
||||||
*/
|
|
||||||
@Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
|
|
||||||
private String concurrent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务状态(0正常 1暂停)
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
@NotBlank(message = "任务名称不能为空")
|
|
||||||
@Size(min = 0, max = 64, message = "任务名称不能超过64个字符")
|
|
||||||
public String getJobName () {
|
|
||||||
return jobName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotBlank(message = "调用目标字符串不能为空")
|
|
||||||
@Size(min = 0, max = 500, message = "调用目标字符串长度不能超过500个字符")
|
|
||||||
public String getInvokeTarget () {
|
|
||||||
return invokeTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotBlank(message = "Cron执行表达式不能为空")
|
|
||||||
@Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")
|
|
||||||
public String getCronExpression () {
|
|
||||||
return cronExpression;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
public Date getNextValidTime () {
|
|
||||||
if (StringUtils.isNotEmpty(cronExpression)) {
|
|
||||||
return CronUtils.getNextExecution(cronExpression);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
package com.muyu.job.domain;
|
|
||||||
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度日志表 sys_job_log
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@SuperBuilder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class SysJobLog extends BaseEntity {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ID
|
|
||||||
*/
|
|
||||||
@Excel(name = "日志序号")
|
|
||||||
private Long jobLogId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务名称
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务名称")
|
|
||||||
private String jobName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务组名
|
|
||||||
*/
|
|
||||||
@Excel(name = "任务组名")
|
|
||||||
private String jobGroup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用目标字符串
|
|
||||||
*/
|
|
||||||
@Excel(name = "调用目标字符串")
|
|
||||||
private String invokeTarget;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日志信息
|
|
||||||
*/
|
|
||||||
@Excel(name = "日志信息")
|
|
||||||
private String jobMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行状态(0正常 1失败)
|
|
||||||
*/
|
|
||||||
@Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 异常信息
|
|
||||||
*/
|
|
||||||
@Excel(name = "异常信息")
|
|
||||||
private String exceptionInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始时间
|
|
||||||
*/
|
|
||||||
private Date startTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 停止时间
|
|
||||||
*/
|
|
||||||
private Date stopTime;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package com.muyu.job.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.muyu.job.domain.SysJobLog;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度任务日志信息 数据层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public interface SysJobLogMapper extends BaseMapper<SysJobLog> {
|
|
||||||
/**
|
|
||||||
* 获取quartz调度器日志的计划任务
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*
|
|
||||||
* @return 调度任务日志集合
|
|
||||||
*/
|
|
||||||
public List<SysJobLog> selectJobLogList (SysJobLog jobLog);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有调度任务日志
|
|
||||||
*
|
|
||||||
* @return 调度任务日志列表
|
|
||||||
*/
|
|
||||||
public List<SysJobLog> selectJobLogAll ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度任务日志ID查询调度信息
|
|
||||||
*
|
|
||||||
* @param jobLogId 调度任务日志ID
|
|
||||||
*
|
|
||||||
* @return 调度任务日志对象信息
|
|
||||||
*/
|
|
||||||
public SysJobLog selectJobLogById (Long jobLogId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增任务日志
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int insertJobLog (SysJobLog jobLog);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度日志信息
|
|
||||||
*
|
|
||||||
* @param logIds 需要删除的数据ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobLogByIds (Long[] logIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务日志
|
|
||||||
*
|
|
||||||
* @param jobId 调度日志ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobLogById (Long jobId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空任务日志
|
|
||||||
*/
|
|
||||||
public void cleanJobLog ();
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package com.muyu.job.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度任务信息 数据层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public interface SysJobMapper extends BaseMapper<SysJob> {
|
|
||||||
/**
|
|
||||||
* 查询调度任务日志集合
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 操作日志集合
|
|
||||||
*/
|
|
||||||
public List<SysJob> selectJobList (SysJob job);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有调度任务
|
|
||||||
*
|
|
||||||
* @return 调度任务列表
|
|
||||||
*/
|
|
||||||
public List<SysJob> selectJobAll ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度ID查询调度任务信息
|
|
||||||
*
|
|
||||||
* @param jobId 调度ID
|
|
||||||
*
|
|
||||||
* @return 角色对象信息
|
|
||||||
*/
|
|
||||||
public SysJob selectJobById (Long jobId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度ID删除调度任务信息
|
|
||||||
*
|
|
||||||
* @param jobId 调度ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobById (Long jobId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度任务信息
|
|
||||||
*
|
|
||||||
* @param ids 需要删除的数据ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobByIds (Long[] ids);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改调度任务信息
|
|
||||||
*
|
|
||||||
* @param job 调度任务信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int updateJob (SysJob job);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增调度任务信息
|
|
||||||
*
|
|
||||||
* @param job 调度任务信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int insertJob (SysJob job);
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package com.muyu.job.service;
|
|
||||||
|
|
||||||
import com.muyu.job.domain.SysJobLog;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度日志信息信息 服务层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public interface ISysJobLogService {
|
|
||||||
/**
|
|
||||||
* 获取quartz调度器日志的计划任务
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*
|
|
||||||
* @return 调度任务日志集合
|
|
||||||
*/
|
|
||||||
public List<SysJobLog> selectJobLogList (SysJobLog jobLog);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度任务日志ID查询调度信息
|
|
||||||
*
|
|
||||||
* @param jobLogId 调度任务日志ID
|
|
||||||
*
|
|
||||||
* @return 调度任务日志对象信息
|
|
||||||
*/
|
|
||||||
public SysJobLog selectJobLogById (Long jobLogId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增任务日志
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*/
|
|
||||||
public void addJobLog (SysJobLog jobLog);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度日志信息
|
|
||||||
*
|
|
||||||
* @param logIds 需要删除的日志ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobLogByIds (Long[] logIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务日志
|
|
||||||
*
|
|
||||||
* @param jobId 调度日志ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJobLogById (Long jobId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空任务日志
|
|
||||||
*/
|
|
||||||
public void cleanJobLog ();
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
package com.muyu.job.service;
|
|
||||||
|
|
||||||
import com.muyu.common.core.exception.job.TaskException;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import org.quartz.SchedulerException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度信息信息 服务层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public interface ISysJobService {
|
|
||||||
/**
|
|
||||||
* 获取quartz调度器的计划任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 调度任务集合
|
|
||||||
*/
|
|
||||||
public List<SysJob> selectJobList (SysJob job);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度任务ID查询调度信息
|
|
||||||
*
|
|
||||||
* @param jobId 调度任务ID
|
|
||||||
*
|
|
||||||
* @return 调度任务对象信息
|
|
||||||
*/
|
|
||||||
public SysJob selectJobById (Long jobId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 暂停任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int pauseJob (SysJob job) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 恢复任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int resumeJob (SysJob job) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务后,所对应的trigger也将被删除
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int deleteJob (SysJob job) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度信息
|
|
||||||
*
|
|
||||||
* @param jobIds 需要删除的任务ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public void deleteJobByIds (Long[] jobIds) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务调度状态修改
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int changeStatus (SysJob job) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 立即运行任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public boolean run (SysJob job) throws SchedulerException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int insertJob (SysJob job) throws SchedulerException, TaskException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int updateJob (SysJob job) throws SchedulerException, TaskException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验cron表达式是否有效
|
|
||||||
*
|
|
||||||
* @param cronExpression 表达式
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public boolean checkCronExpressionIsValid (String cronExpression);
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
package com.muyu.job.service;
|
|
||||||
|
|
||||||
import com.muyu.job.domain.SysJobLog;
|
|
||||||
import com.muyu.job.mapper.SysJobLogMapper;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度日志信息 服务层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class SysJobLogServiceImpl implements ISysJobLogService {
|
|
||||||
@Autowired
|
|
||||||
private SysJobLogMapper jobLogMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取quartz调度器日志的计划任务
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*
|
|
||||||
* @return 调度任务日志集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<SysJobLog> selectJobLogList (SysJobLog jobLog) {
|
|
||||||
return jobLogMapper.selectJobLogList(jobLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度任务日志ID查询调度信息
|
|
||||||
*
|
|
||||||
* @param jobLogId 调度任务日志ID
|
|
||||||
*
|
|
||||||
* @return 调度任务日志对象信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public SysJobLog selectJobLogById (Long jobLogId) {
|
|
||||||
return jobLogMapper.selectJobLogById(jobLogId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增任务日志
|
|
||||||
*
|
|
||||||
* @param jobLog 调度日志信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addJobLog (SysJobLog jobLog) {
|
|
||||||
jobLogMapper.insertJobLog(jobLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度日志信息
|
|
||||||
*
|
|
||||||
* @param logIds 需要删除的数据ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int deleteJobLogByIds (Long[] logIds) {
|
|
||||||
return jobLogMapper.deleteJobLogByIds(logIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务日志
|
|
||||||
*
|
|
||||||
* @param jobId 调度日志ID
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int deleteJobLogById (Long jobId) {
|
|
||||||
return jobLogMapper.deleteJobLogById(jobId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空任务日志
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void cleanJobLog () {
|
|
||||||
jobLogMapper.cleanJobLog();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,239 +0,0 @@
|
||||||
package com.muyu.job.service;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.ScheduleConstants;
|
|
||||||
import com.muyu.common.core.exception.job.TaskException;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import com.muyu.job.mapper.SysJobMapper;
|
|
||||||
import com.muyu.job.util.CronUtils;
|
|
||||||
import com.muyu.job.util.ScheduleUtils;
|
|
||||||
import org.quartz.JobDataMap;
|
|
||||||
import org.quartz.JobKey;
|
|
||||||
import org.quartz.Scheduler;
|
|
||||||
import org.quartz.SchedulerException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度信息 服务层
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class SysJobServiceImpl implements ISysJobService {
|
|
||||||
@Autowired
|
|
||||||
private Scheduler scheduler;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysJobMapper jobMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
|
||||||
*/
|
|
||||||
@PostConstruct
|
|
||||||
public void init () throws SchedulerException, TaskException {
|
|
||||||
scheduler.clear();
|
|
||||||
List<SysJob> jobList = jobMapper.selectJobAll();
|
|
||||||
for (SysJob job : jobList) {
|
|
||||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取quartz调度器的计划任务列表
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<SysJob> selectJobList (SysJob job) {
|
|
||||||
return jobMapper.selectJobList(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过调度任务ID查询调度信息
|
|
||||||
*
|
|
||||||
* @param jobId 调度任务ID
|
|
||||||
*
|
|
||||||
* @return 调度任务对象信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public SysJob selectJobById (Long jobId) {
|
|
||||||
return jobMapper.selectJobById(jobId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 暂停任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int pauseJob (SysJob job) throws SchedulerException {
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
String jobGroup = job.getJobGroup();
|
|
||||||
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
|
||||||
int rows = jobMapper.updateJob(job);
|
|
||||||
if (rows > 0) {
|
|
||||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 恢复任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int resumeJob (SysJob job) throws SchedulerException {
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
String jobGroup = job.getJobGroup();
|
|
||||||
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
|
||||||
int rows = jobMapper.updateJob(job);
|
|
||||||
if (rows > 0) {
|
|
||||||
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务后,所对应的trigger也将被删除
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int deleteJob (SysJob job) throws SchedulerException {
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
String jobGroup = job.getJobGroup();
|
|
||||||
int rows = jobMapper.deleteJobById(jobId);
|
|
||||||
if (rows > 0) {
|
|
||||||
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除调度信息
|
|
||||||
*
|
|
||||||
* @param jobIds 需要删除的任务ID
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void deleteJobByIds (Long[] jobIds) throws SchedulerException {
|
|
||||||
for (Long jobId : jobIds) {
|
|
||||||
SysJob job = jobMapper.selectJobById(jobId);
|
|
||||||
deleteJob(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务调度状态修改
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int changeStatus (SysJob job) throws SchedulerException {
|
|
||||||
int rows = 0;
|
|
||||||
String status = job.getStatus();
|
|
||||||
if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
|
|
||||||
rows = resumeJob(job);
|
|
||||||
} else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
|
|
||||||
rows = pauseJob(job);
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 立即运行任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean run (SysJob job) throws SchedulerException {
|
|
||||||
boolean result = false;
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
String jobGroup = job.getJobGroup();
|
|
||||||
SysJob properties = selectJobById(job.getJobId());
|
|
||||||
// 参数
|
|
||||||
JobDataMap dataMap = new JobDataMap();
|
|
||||||
dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
|
|
||||||
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
|
||||||
if (scheduler.checkExists(jobKey)) {
|
|
||||||
result = true;
|
|
||||||
scheduler.triggerJob(jobKey, dataMap);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增任务
|
|
||||||
*
|
|
||||||
* @param job 调度信息 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int insertJob (SysJob job) throws SchedulerException, TaskException {
|
|
||||||
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
|
||||||
int rows = jobMapper.insertJob(job);
|
|
||||||
if (rows > 0) {
|
|
||||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新任务的时间表达式
|
|
||||||
*
|
|
||||||
* @param job 调度信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public int updateJob (SysJob job) throws SchedulerException, TaskException {
|
|
||||||
SysJob properties = selectJobById(job.getJobId());
|
|
||||||
int rows = jobMapper.updateJob(job);
|
|
||||||
if (rows > 0) {
|
|
||||||
updateSchedulerJob(job, properties.getJobGroup());
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新任务
|
|
||||||
*
|
|
||||||
* @param job 任务对象
|
|
||||||
* @param jobGroup 任务组名
|
|
||||||
*/
|
|
||||||
public void updateSchedulerJob (SysJob job, String jobGroup) throws SchedulerException, TaskException {
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
// 判断是否存在
|
|
||||||
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
|
||||||
if (scheduler.checkExists(jobKey)) {
|
|
||||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
|
||||||
scheduler.deleteJob(jobKey);
|
|
||||||
}
|
|
||||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验cron表达式是否有效
|
|
||||||
*
|
|
||||||
* @param cronExpression 表达式
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean checkCronExpressionIsValid (String cronExpression) {
|
|
||||||
return CronUtils.isValid(cronExpression);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.muyu.job.task;
|
|
||||||
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务调度测试
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Component("myTask")
|
|
||||||
public class MyTask {
|
|
||||||
public void ryMultipleParams (String s, Boolean b, Long l, Double d, Integer i) {
|
|
||||||
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ryParams (String params) {
|
|
||||||
System.out.println("执行有参方法:" + params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ryNoParams () {
|
|
||||||
System.out.println("执行无参方法");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.ScheduleConstants;
|
|
||||||
import com.muyu.common.core.utils.ExceptionUtil;
|
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import com.muyu.common.core.utils.bean.BeanUtils;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import com.muyu.job.domain.SysJobLog;
|
|
||||||
import com.muyu.job.service.ISysJobLogService;
|
|
||||||
import org.quartz.Job;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
import org.quartz.JobExecutionException;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 抽象quartz调用
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public abstract class AbstractQuartzJob implements Job {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线程本地变量
|
|
||||||
*/
|
|
||||||
private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute (JobExecutionContext context) throws JobExecutionException {
|
|
||||||
SysJob sysJob = new SysJob();
|
|
||||||
BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
|
||||||
try {
|
|
||||||
before(context, sysJob);
|
|
||||||
if (sysJob != null) {
|
|
||||||
doExecute(context, sysJob);
|
|
||||||
}
|
|
||||||
after(context, sysJob, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("任务执行异常 - :", e);
|
|
||||||
after(context, sysJob, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行前
|
|
||||||
*
|
|
||||||
* @param context 工作执行上下文对象
|
|
||||||
* @param sysJob 系统计划任务
|
|
||||||
*/
|
|
||||||
protected void before (JobExecutionContext context, SysJob sysJob) {
|
|
||||||
threadLocal.set(new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行后
|
|
||||||
*
|
|
||||||
* @param context 工作执行上下文对象
|
|
||||||
* @param sysJob 系统计划任务
|
|
||||||
*/
|
|
||||||
protected void after (JobExecutionContext context, SysJob sysJob, Exception e) {
|
|
||||||
Date startTime = threadLocal.get();
|
|
||||||
threadLocal.remove();
|
|
||||||
|
|
||||||
final SysJobLog sysJobLog = new SysJobLog();
|
|
||||||
sysJobLog.setJobName(sysJob.getJobName());
|
|
||||||
sysJobLog.setJobGroup(sysJob.getJobGroup());
|
|
||||||
sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
|
|
||||||
sysJobLog.setStartTime(startTime);
|
|
||||||
sysJobLog.setStopTime(new Date());
|
|
||||||
long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
|
|
||||||
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
|
|
||||||
if (e != null) {
|
|
||||||
sysJobLog.setStatus("1");
|
|
||||||
String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
|
||||||
sysJobLog.setExceptionInfo(errorMsg);
|
|
||||||
} else {
|
|
||||||
sysJobLog.setStatus("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入数据库当中
|
|
||||||
SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行方法,由子类重载
|
|
||||||
*
|
|
||||||
* @param context 工作执行上下文对象
|
|
||||||
* @param sysJob 系统计划任务
|
|
||||||
*
|
|
||||||
* @throws Exception 执行过程中的异常
|
|
||||||
*/
|
|
||||||
protected abstract void doExecute (JobExecutionContext context, SysJob sysJob) throws Exception;
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import org.quartz.CronExpression;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cron表达式工具类
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class CronUtils {
|
|
||||||
/**
|
|
||||||
* 返回一个布尔值代表一个给定的Cron表达式的有效性
|
|
||||||
*
|
|
||||||
* @param cronExpression Cron表达式
|
|
||||||
*
|
|
||||||
* @return boolean 表达式是否有效
|
|
||||||
*/
|
|
||||||
public static boolean isValid (String cronExpression) {
|
|
||||||
return CronExpression.isValidExpression(cronExpression);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回一个字符串值,表示该消息无效Cron表达式给出有效性
|
|
||||||
*
|
|
||||||
* @param cronExpression Cron表达式
|
|
||||||
*
|
|
||||||
* @return String 无效时返回表达式错误描述,如果有效返回null
|
|
||||||
*/
|
|
||||||
public static String getInvalidMessage (String cronExpression) {
|
|
||||||
try {
|
|
||||||
new CronExpression(cronExpression);
|
|
||||||
return null;
|
|
||||||
} catch (ParseException pe) {
|
|
||||||
return pe.getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回下一个执行时间根据给定的Cron表达式
|
|
||||||
*
|
|
||||||
* @param cronExpression Cron表达式
|
|
||||||
*
|
|
||||||
* @return Date 下次Cron表达式执行时间
|
|
||||||
*/
|
|
||||||
public static Date getNextExecution (String cronExpression) {
|
|
||||||
try {
|
|
||||||
CronExpression cron = new CronExpression(cronExpression);
|
|
||||||
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new IllegalArgumentException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,165 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务执行工具
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class JobInvokeUtil {
|
|
||||||
/**
|
|
||||||
* 执行方法
|
|
||||||
*
|
|
||||||
* @param sysJob 系统任务
|
|
||||||
*/
|
|
||||||
public static void invokeMethod (SysJob sysJob) throws Exception {
|
|
||||||
String invokeTarget = sysJob.getInvokeTarget();
|
|
||||||
String beanName = getBeanName(invokeTarget);
|
|
||||||
String methodName = getMethodName(invokeTarget);
|
|
||||||
List<Object[]> methodParams = getMethodParams(invokeTarget);
|
|
||||||
|
|
||||||
if (!isValidClassName(beanName)) {
|
|
||||||
Object bean = SpringUtils.getBean(beanName);
|
|
||||||
invokeMethod(bean, methodName, methodParams);
|
|
||||||
} else {
|
|
||||||
Object bean = Class.forName(beanName).getDeclaredConstructor().newInstance();
|
|
||||||
invokeMethod(bean, methodName, methodParams);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用任务方法
|
|
||||||
*
|
|
||||||
* @param bean 目标对象
|
|
||||||
* @param methodName 方法名称
|
|
||||||
* @param methodParams 方法参数
|
|
||||||
*/
|
|
||||||
private static void invokeMethod (Object bean, String methodName, List<Object[]> methodParams)
|
|
||||||
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
|
||||||
InvocationTargetException {
|
|
||||||
if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) {
|
|
||||||
Method method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams));
|
|
||||||
method.invoke(bean, getMethodParamsValue(methodParams));
|
|
||||||
} else {
|
|
||||||
Method method = bean.getClass().getMethod(methodName);
|
|
||||||
method.invoke(bean);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验是否为为class包名
|
|
||||||
*
|
|
||||||
* @param invokeTarget 名称
|
|
||||||
*
|
|
||||||
* @return true是 false否
|
|
||||||
*/
|
|
||||||
public static boolean isValidClassName (String invokeTarget) {
|
|
||||||
return StringUtils.countMatches(invokeTarget, ".") > 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取bean名称
|
|
||||||
*
|
|
||||||
* @param invokeTarget 目标字符串
|
|
||||||
*
|
|
||||||
* @return bean名称
|
|
||||||
*/
|
|
||||||
public static String getBeanName (String invokeTarget) {
|
|
||||||
String beanName = StringUtils.substringBefore(invokeTarget, "(");
|
|
||||||
return StringUtils.substringBeforeLast(beanName, ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取bean方法
|
|
||||||
*
|
|
||||||
* @param invokeTarget 目标字符串
|
|
||||||
*
|
|
||||||
* @return method方法
|
|
||||||
*/
|
|
||||||
public static String getMethodName (String invokeTarget) {
|
|
||||||
String methodName = StringUtils.substringBefore(invokeTarget, "(");
|
|
||||||
return StringUtils.substringAfterLast(methodName, ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取method方法参数相关列表
|
|
||||||
*
|
|
||||||
* @param invokeTarget 目标字符串
|
|
||||||
*
|
|
||||||
* @return method方法相关参数列表
|
|
||||||
*/
|
|
||||||
public static List<Object[]> getMethodParams (String invokeTarget) {
|
|
||||||
String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
|
|
||||||
if (StringUtils.isEmpty(methodStr)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String[] methodParams = methodStr.split(",(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
|
||||||
List<Object[]> classs = new LinkedList<>();
|
|
||||||
for (int i = 0 ; i < methodParams.length ; i++) {
|
|
||||||
String str = StringUtils.trimToEmpty(methodParams[i]);
|
|
||||||
// String字符串类型,以'或"开头
|
|
||||||
if (StringUtils.startsWithAny(str, "'", "\"")) {
|
|
||||||
classs.add(new Object[]{StringUtils.substring(str, 1, str.length() - 1), String.class});
|
|
||||||
}
|
|
||||||
// boolean布尔类型,等于true或者false
|
|
||||||
else if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) {
|
|
||||||
classs.add(new Object[]{Boolean.valueOf(str), Boolean.class});
|
|
||||||
}
|
|
||||||
// long长整形,以L结尾
|
|
||||||
else if (StringUtils.endsWith(str, "L")) {
|
|
||||||
classs.add(new Object[]{Long.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Long.class});
|
|
||||||
}
|
|
||||||
// double浮点类型,以D结尾
|
|
||||||
else if (StringUtils.endsWith(str, "D")) {
|
|
||||||
classs.add(new Object[]{Double.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Double.class});
|
|
||||||
}
|
|
||||||
// 其他类型归类为整形
|
|
||||||
else {
|
|
||||||
classs.add(new Object[]{Integer.valueOf(str), Integer.class});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return classs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取参数类型
|
|
||||||
*
|
|
||||||
* @param methodParams 参数相关列表
|
|
||||||
*
|
|
||||||
* @return 参数类型列表
|
|
||||||
*/
|
|
||||||
public static Class<?>[] getMethodParamsType (List<Object[]> methodParams) {
|
|
||||||
Class<?>[] classs = new Class<?>[methodParams.size()];
|
|
||||||
int index = 0;
|
|
||||||
for (Object[] os : methodParams) {
|
|
||||||
classs[index] = (Class<?>) os[1];
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
return classs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取参数值
|
|
||||||
*
|
|
||||||
* @param methodParams 参数相关列表
|
|
||||||
*
|
|
||||||
* @return 参数值列表
|
|
||||||
*/
|
|
||||||
public static Object[] getMethodParamsValue (List<Object[]> methodParams) {
|
|
||||||
Object[] classs = new Object[methodParams.size()];
|
|
||||||
int index = 0;
|
|
||||||
for (Object[] os : methodParams) {
|
|
||||||
classs[index] = (Object) os[0];
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
return classs;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import org.quartz.DisallowConcurrentExecution;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务处理(禁止并发执行)
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@DisallowConcurrentExecution
|
|
||||||
public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob {
|
|
||||||
@Override
|
|
||||||
protected void doExecute (JobExecutionContext context, SysJob sysJob) throws Exception {
|
|
||||||
JobInvokeUtil.invokeMethod(sysJob);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务处理(允许并发执行)
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class QuartzJobExecution extends AbstractQuartzJob {
|
|
||||||
@Override
|
|
||||||
protected void doExecute (JobExecutionContext context, SysJob sysJob) throws Exception {
|
|
||||||
JobInvokeUtil.invokeMethod(sysJob);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,121 +0,0 @@
|
||||||
package com.muyu.job.util;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.Constants;
|
|
||||||
import com.muyu.common.core.constant.ScheduleConstants;
|
|
||||||
import com.muyu.common.core.exception.job.TaskException;
|
|
||||||
import com.muyu.common.core.exception.job.TaskException.Code;
|
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import com.muyu.job.domain.SysJob;
|
|
||||||
import org.quartz.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时任务工具类
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class ScheduleUtils {
|
|
||||||
/**
|
|
||||||
* 得到quartz任务类
|
|
||||||
*
|
|
||||||
* @param sysJob 执行计划
|
|
||||||
*
|
|
||||||
* @return 具体执行任务类
|
|
||||||
*/
|
|
||||||
private static Class<? extends Job> getQuartzJobClass (SysJob sysJob) {
|
|
||||||
boolean isConcurrent = "0".equals(sysJob.getConcurrent());
|
|
||||||
return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建任务触发对象
|
|
||||||
*/
|
|
||||||
public static TriggerKey getTriggerKey (Long jobId, String jobGroup) {
|
|
||||||
return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建任务键对象
|
|
||||||
*/
|
|
||||||
public static JobKey getJobKey (Long jobId, String jobGroup) {
|
|
||||||
return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建定时任务
|
|
||||||
*/
|
|
||||||
public static void createScheduleJob (Scheduler scheduler, SysJob job) throws SchedulerException, TaskException {
|
|
||||||
Class<? extends Job> jobClass = getQuartzJobClass(job);
|
|
||||||
// 构建job信息
|
|
||||||
Long jobId = job.getJobId();
|
|
||||||
String jobGroup = job.getJobGroup();
|
|
||||||
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();
|
|
||||||
|
|
||||||
// 表达式调度构建器
|
|
||||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
|
||||||
cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
|
|
||||||
|
|
||||||
// 按新的cronExpression表达式构建一个新的trigger
|
|
||||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
|
|
||||||
.withSchedule(cronScheduleBuilder).build();
|
|
||||||
|
|
||||||
// 放入参数,运行时的方法可以获取
|
|
||||||
jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
|
|
||||||
|
|
||||||
// 判断是否存在
|
|
||||||
if (scheduler.checkExists(getJobKey(jobId, jobGroup))) {
|
|
||||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
|
||||||
scheduler.deleteJob(getJobKey(jobId, jobGroup));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断任务是否过期
|
|
||||||
if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression()))) {
|
|
||||||
// 执行调度任务
|
|
||||||
scheduler.scheduleJob(jobDetail, trigger);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 暂停任务
|
|
||||||
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) {
|
|
||||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置定时任务策略
|
|
||||||
*/
|
|
||||||
public static CronScheduleBuilder handleCronScheduleMisfirePolicy (SysJob job, CronScheduleBuilder cb)
|
|
||||||
throws TaskException {
|
|
||||||
switch (job.getMisfirePolicy()) {
|
|
||||||
case ScheduleConstants.MISFIRE_DEFAULT:
|
|
||||||
return cb;
|
|
||||||
case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
|
|
||||||
return cb.withMisfireHandlingInstructionIgnoreMisfires();
|
|
||||||
case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
|
|
||||||
return cb.withMisfireHandlingInstructionFireAndProceed();
|
|
||||||
case ScheduleConstants.MISFIRE_DO_NOTHING:
|
|
||||||
return cb.withMisfireHandlingInstructionDoNothing();
|
|
||||||
default:
|
|
||||||
throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
|
|
||||||
+ "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查包名是否为白名单配置
|
|
||||||
*
|
|
||||||
* @param invokeTarget 目标字符串
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public static boolean whiteList (String invokeTarget) {
|
|
||||||
String packageName = StringUtils.substringBefore(invokeTarget, "(");
|
|
||||||
int count = StringUtils.countMatches(packageName, ".");
|
|
||||||
if (count > 1) {
|
|
||||||
return StringUtils.containsAnyIgnoreCase(invokeTarget, Constants.JOB_WHITELIST_STR);
|
|
||||||
}
|
|
||||||
Object obj = SpringUtils.getBean(StringUtils.split(invokeTarget, ".")[0]);
|
|
||||||
String beanPackageName = obj.getClass().getPackage().getName();
|
|
||||||
return StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_WHITELIST_STR)
|
|
||||||
&& !StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_ERROR_STR);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
Spring Boot Version: ${spring-boot.version}
|
|
||||||
Spring Application Name: ${spring.application.name}
|
|
|
@ -1,49 +0,0 @@
|
||||||
# Tomcat
|
|
||||||
server:
|
|
||||||
port: 9203
|
|
||||||
|
|
||||||
# nacos线上地址
|
|
||||||
nacos:
|
|
||||||
addr: 47.92.86.60:8848
|
|
||||||
user-name: nacos
|
|
||||||
password: nacos
|
|
||||||
namespace: muyu-cloud
|
|
||||||
|
|
||||||
# Spring
|
|
||||||
spring:
|
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
application:
|
|
||||||
# 应用名称
|
|
||||||
name: cloud-job
|
|
||||||
profiles:
|
|
||||||
# 环境配置
|
|
||||||
active: dev
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
# 服务注册地址
|
|
||||||
server-addr: ${nacos.addr}
|
|
||||||
# nacos用户名
|
|
||||||
username: ${nacos.user-name}
|
|
||||||
# nacos密码
|
|
||||||
password: ${nacos.password}
|
|
||||||
# 命名空间
|
|
||||||
namespace: ${nacos.namespace}
|
|
||||||
config:
|
|
||||||
# 服务注册地址
|
|
||||||
server-addr: ${nacos.addr}
|
|
||||||
# nacos用户名
|
|
||||||
username: ${nacos.user-name}
|
|
||||||
# nacos密码
|
|
||||||
password: ${nacos.password}
|
|
||||||
# 命名空间
|
|
||||||
namespace: ${nacos.namespace}
|
|
||||||
# 配置文件格式
|
|
||||||
file-extension: yml
|
|
||||||
# 共享配置
|
|
||||||
shared-configs:
|
|
||||||
# 系统共享配置
|
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
||||||
# 系统环境Config共享配置
|
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
|
@ -1,74 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-job"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-job"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
|
||||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
|
||||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
|
||||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
|
||||||
<Pattern>${log.sky.pattern}</Pattern>
|
|
||||||
</layout>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="GRPC_LOG"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-job"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
|
||||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
|
||||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
|
||||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
|
||||||
<Pattern>${log.sky.pattern}</Pattern>
|
|
||||||
</layout>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="GRPC_LOG"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -1,102 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.muyu.job.mapper.SysJobLogMapper">
|
|
||||||
|
|
||||||
<resultMap type="com.muyu.job.domain.SysJobLog" id="SysJobLogResult">
|
|
||||||
<id property="jobLogId" column="job_log_id"/>
|
|
||||||
<result property="jobName" column="job_name"/>
|
|
||||||
<result property="jobGroup" column="job_group"/>
|
|
||||||
<result property="invokeTarget" column="invoke_target"/>
|
|
||||||
<result property="jobMessage" column="job_message"/>
|
|
||||||
<result property="status" column="status"/>
|
|
||||||
<result property="exceptionInfo" column="exception_info"/>
|
|
||||||
<result property="createTime" column="create_time"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<sql id="selectJobLogVo">
|
|
||||||
select job_log_id,
|
|
||||||
job_name,
|
|
||||||
job_group,
|
|
||||||
invoke_target,
|
|
||||||
job_message,
|
|
||||||
status,
|
|
||||||
exception_info,
|
|
||||||
create_time
|
|
||||||
from sys_job_log
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<select id="selectJobLogList" parameterType="com.muyu.job.domain.SysJobLog" resultMap="SysJobLogResult">
|
|
||||||
<include refid="selectJobLogVo"/>
|
|
||||||
<where>
|
|
||||||
<if test="jobName != null and jobName != ''">
|
|
||||||
AND job_name like concat('%', #{jobName}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">
|
|
||||||
AND job_group = #{jobGroup}
|
|
||||||
</if>
|
|
||||||
<if test="status != null and status != ''">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">
|
|
||||||
AND invoke_target like concat('%', #{invokeTarget}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
|
||||||
and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
|
||||||
</if>
|
|
||||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
|
||||||
and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectJobLogAll" resultMap="SysJobLogResult">
|
|
||||||
<include refid="selectJobLogVo"/>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult">
|
|
||||||
<include refid="selectJobLogVo"/>
|
|
||||||
where job_log_id = #{jobLogId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<delete id="deleteJobLogById" parameterType="Long">
|
|
||||||
delete
|
|
||||||
from sys_job_log
|
|
||||||
where job_log_id = #{jobLogId}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<delete id="deleteJobLogByIds" parameterType="Long">
|
|
||||||
delete from sys_job_log where job_log_id in
|
|
||||||
<foreach collection="array" item="jobLogId" open="(" separator="," close=")">
|
|
||||||
#{jobLogId}
|
|
||||||
</foreach>
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<update id="cleanJobLog">
|
|
||||||
truncate table sys_job_log
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<insert id="insertJobLog" parameterType="com.muyu.job.domain.SysJobLog">
|
|
||||||
insert into sys_job_log(
|
|
||||||
<if test="jobLogId != null and jobLogId != 0">job_log_id,</if>
|
|
||||||
<if test="jobName != null and jobName != ''">job_name,</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
|
||||||
<if test="jobMessage != null and jobMessage != ''">job_message,</if>
|
|
||||||
<if test="status != null and status != ''">status,</if>
|
|
||||||
<if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if>
|
|
||||||
create_time
|
|
||||||
)values(
|
|
||||||
<if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if>
|
|
||||||
<if test="jobName != null and jobName != ''">#{jobName},</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
|
||||||
<if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if>
|
|
||||||
<if test="status != null and status != ''">#{status},</if>
|
|
||||||
<if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if>
|
|
||||||
sysdate()
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -1,123 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.muyu.job.mapper.SysJobMapper">
|
|
||||||
|
|
||||||
<resultMap type="com.muyu.job.domain.SysJob" id="SysJobResult">
|
|
||||||
<id property="jobId" column="job_id"/>
|
|
||||||
<result property="jobName" column="job_name"/>
|
|
||||||
<result property="jobGroup" column="job_group"/>
|
|
||||||
<result property="invokeTarget" column="invoke_target"/>
|
|
||||||
<result property="cronExpression" column="cron_expression"/>
|
|
||||||
<result property="misfirePolicy" column="misfire_policy"/>
|
|
||||||
<result property="concurrent" column="concurrent"/>
|
|
||||||
<result property="status" column="status"/>
|
|
||||||
<result property="createBy" column="create_by"/>
|
|
||||||
<result property="createTime" column="create_time"/>
|
|
||||||
<result property="updateBy" column="update_by"/>
|
|
||||||
<result property="updateTime" column="update_time"/>
|
|
||||||
<result property="remark" column="remark"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<sql id="selectJobVo">
|
|
||||||
select job_id,
|
|
||||||
job_name,
|
|
||||||
job_group,
|
|
||||||
invoke_target,
|
|
||||||
cron_expression,
|
|
||||||
misfire_policy,
|
|
||||||
concurrent,
|
|
||||||
status,
|
|
||||||
create_by,
|
|
||||||
create_time,
|
|
||||||
remark
|
|
||||||
from sys_job
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<select id="selectJobList" parameterType="com.muyu.job.domain.SysJob" resultMap="SysJobResult">
|
|
||||||
<include refid="selectJobVo"/>
|
|
||||||
<where>
|
|
||||||
<if test="jobName != null and jobName != ''">
|
|
||||||
AND job_name like concat('%', #{jobName}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">
|
|
||||||
AND job_group = #{jobGroup}
|
|
||||||
</if>
|
|
||||||
<if test="status != null and status != ''">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">
|
|
||||||
AND invoke_target like concat('%', #{invokeTarget}, '%')
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectJobAll" resultMap="SysJobResult">
|
|
||||||
<include refid="selectJobVo"/>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectJobById" parameterType="Long" resultMap="SysJobResult">
|
|
||||||
<include refid="selectJobVo"/>
|
|
||||||
where job_id = #{jobId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<delete id="deleteJobById" parameterType="Long">
|
|
||||||
delete
|
|
||||||
from sys_job
|
|
||||||
where job_id = #{jobId}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<delete id="deleteJobByIds" parameterType="Long">
|
|
||||||
delete from sys_job where job_id in
|
|
||||||
<foreach collection="array" item="jobId" open="(" separator="," close=")">
|
|
||||||
#{jobId}
|
|
||||||
</foreach>
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<update id="updateJob" parameterType="com.muyu.job.domain.SysJob">
|
|
||||||
update sys_job
|
|
||||||
<set>
|
|
||||||
<if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>
|
|
||||||
<if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
|
|
||||||
<if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if>
|
|
||||||
<if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if>
|
|
||||||
<if test="status !=null">status = #{status},</if>
|
|
||||||
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
|
||||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
|
||||||
update_time = sysdate()
|
|
||||||
</set>
|
|
||||||
where job_id = #{jobId}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<insert id="insertJob" parameterType="com.muyu.job.domain.SysJob" useGeneratedKeys="true" keyProperty="jobId">
|
|
||||||
insert into sys_job(
|
|
||||||
<if test="jobId != null and jobId != 0">job_id,</if>
|
|
||||||
<if test="jobName != null and jobName != ''">job_name,</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">job_group,</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
|
|
||||||
<if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
|
|
||||||
<if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if>
|
|
||||||
<if test="concurrent != null and concurrent != ''">concurrent,</if>
|
|
||||||
<if test="status != null and status != ''">status,</if>
|
|
||||||
<if test="remark != null and remark != ''">remark,</if>
|
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
|
||||||
create_time
|
|
||||||
)values(
|
|
||||||
<if test="jobId != null and jobId != 0">#{jobId},</if>
|
|
||||||
<if test="jobName != null and jobName != ''">#{jobName},</if>
|
|
||||||
<if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
|
|
||||||
<if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
|
|
||||||
<if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
|
|
||||||
<if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if>
|
|
||||||
<if test="concurrent != null and concurrent != ''">#{concurrent},</if>
|
|
||||||
<if test="status != null and status != ''">#{status},</if>
|
|
||||||
<if test="remark != null and remark != ''">#{remark},</if>
|
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
|
||||||
sysdate()
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -41,13 +41,6 @@
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger UI -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
<!-- Mysql Connector -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
|
@ -72,15 +65,16 @@
|
||||||
<artifactId>cloud-common-log</artifactId>
|
<artifactId>cloud-common-log</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- MuYu Common Swagger -->
|
<!-- 接口模块 -->
|
||||||
<!--<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
|
||||||
</dependency>-->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- XllJob定时任务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.system;
|
||||||
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
//import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.system.domain.SysConfig;
|
import com.muyu.system.domain.SysConfig;
|
||||||
import com.muyu.system.service.SysConfigService;
|
import com.muyu.system.service.SysConfigService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/config")
|
@RequestMapping("/config")
|
||||||
|
@Tag(name = "SysConfigController", description = "系统参数配置")
|
||||||
public class SysConfigController extends BaseController {
|
public class SysConfigController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -35,6 +38,7 @@ public class SysConfigController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:config:list")
|
@RequiresPermissions("system:config:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "查询集合", description = "更新水果信息")
|
||||||
public Result<TableDataInfo<SysConfig>> list (SysConfig config) {
|
public Result<TableDataInfo<SysConfig>> list (SysConfig config) {
|
||||||
startPage();
|
startPage();
|
||||||
List<SysConfig> list = configService.pageQuery(config);
|
List<SysConfig> list = configService.pageQuery(config);
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
@ -47,6 +47,8 @@ spring:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
# 系统环境Config共享配置
|
# 系统环境Config共享配置
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# xxl-job 配置文件
|
||||||
|
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.muyu.system.mapper: DEBUG
|
com.muyu.system.mapper: DEBUG
|
|
@ -11,7 +11,6 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>cloud-modules-system</module>
|
<module>cloud-modules-system</module>
|
||||||
<module>cloud-modules-gen</module>
|
<module>cloud-modules-gen</module>
|
||||||
<module>cloud-modules-job</module>
|
|
||||||
<module>cloud-modules-file</module>
|
<module>cloud-modules-file</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.92.86.60:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: muyu-cloud
|
namespace: muyu-cloud
|
||||||
|
|
24
pom.xml
24
pom.xml
|
@ -40,6 +40,8 @@
|
||||||
<jakarta.servlet.version>6.1.0-M2</jakarta.servlet.version>
|
<jakarta.servlet.version>6.1.0-M2</jakarta.servlet.version>
|
||||||
<javax.annotation.version>1.3.2</javax.annotation.version>
|
<javax.annotation.version>1.3.2</javax.annotation.version>
|
||||||
<hutool.version>5.8.27</hutool.version>
|
<hutool.version>5.8.27</hutool.version>
|
||||||
|
<knife4j-openapi3.version>4.1.0</knife4j-openapi3.version>
|
||||||
|
<xxl-job-core.version>2.4.1</xxl-job-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
|
@ -86,6 +88,13 @@
|
||||||
<version>${apm-logback.version}</version>
|
<version>${apm-logback.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- knife4j-openapi3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||||
|
<version>${knife4j-openapi3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Java jakarta Servlet -->
|
<!-- Java jakarta Servlet -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
|
@ -184,7 +193,7 @@
|
||||||
<!-- 接口模块 -->
|
<!-- 接口模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
<version>${muyu.version}</version>
|
<version>${muyu.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -237,6 +246,19 @@
|
||||||
<version>${muyu.version}</version>
|
<version>${muyu.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- xxl-job-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
<version>${xxl-job-core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- XllJob定时任务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
|
<version>${muyu.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
skywalking-oap-server-9.7.0-java17: https://www.kdocs.cn/l/cmEiIEKglupf
|
||||||
|
skywalking-ui-9.7.0-java17: https://www.kdocs.cn/l/ctyJvGn0z7bZ
|
||||||
|
|
||||||
|
文件下载下来之后使用{docker load < [文件]}这个命令进行加载到docker当中
|
||||||
|
|
||||||
|
链路追踪-SkyWalking安装参考地址: https://kdocs.cn/l/ceValb05jXOA
|
|
@ -0,0 +1,33 @@
|
||||||
|
### web 如果要改变端口和这个访问前缀在此进行更改
|
||||||
|
### 原端口是8080
|
||||||
|
server.port=80
|
||||||
|
### 原请求路径是/xxl-job-admin
|
||||||
|
server.servlet.context-path=/
|
||||||
|
### 调度中心JDBC链接:链接地址请保持和 2.1章节 所创建的调度数据库的地址一致
|
||||||
|
spring.datasource.url=jdbc:mysql://xxl-mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=root
|
||||||
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
|
|
||||||
|
### 报警邮箱
|
||||||
|
spring.mail.host= smtp.163.com
|
||||||
|
spring.mail.port=465
|
||||||
|
spring.mail.username=dongzl828@163.com
|
||||||
|
spring.mail.password=EGHEDRZUIZWUIGZY
|
||||||
|
spring.mail.properties.mail.smtp.auth=true
|
||||||
|
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||||
|
spring.mail.properties.mail.smtp.starttls.required=true
|
||||||
|
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
|
||||||
|
|
||||||
|
### 调度中心通讯TOKEN [选填]:非空时启用;
|
||||||
|
xxl.job.accessToken=
|
||||||
|
|
||||||
|
### 调度中心国际化配置 [必填]: 默认为 "zh_CN"/中文简体, 可选范围为 "zh_CN"/中文简体, "zh_TC"/中文繁体 and "en"/英文;
|
||||||
|
xxl.job.i18n=zh_CN
|
||||||
|
|
||||||
|
## 调度线程池最大线程配置【必填】
|
||||||
|
xxl.job.triggerpool.fast.max=200
|
||||||
|
xxl.job.triggerpool.slow.max=100
|
||||||
|
|
||||||
|
### 调度中心日志表数据保存天数 [必填]:过期日志自动清理;限制大于等于7时生效,否则, 如-1,关闭自动清理功能;
|
||||||
|
xxl.job.logretentiondays=30
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
docker run --name xxl-job-admin -d \
|
||||||
|
--network xxl-network \
|
||||||
|
-v ./config/application.properties:/config/application.properties \
|
||||||
|
-e PARAMS="--spring.config.additional-location=/config/application.properties" \
|
||||||
|
-v ./log:/data/applogs \
|
||||||
|
xuxueli/xxl-job-admin:2.4.1
|
|
@ -0,0 +1,66 @@
|
||||||
|
[client]
|
||||||
|
# 端口号
|
||||||
|
port=3306
|
||||||
|
default-character-set=utf8mb4
|
||||||
|
|
||||||
|
[mysql]
|
||||||
|
no-beep
|
||||||
|
default-character-set=utf8mb4
|
||||||
|
|
||||||
|
[mysqld]
|
||||||
|
# 端口号
|
||||||
|
port=3306
|
||||||
|
# 数据目录
|
||||||
|
datadir=/var/lib/mysql
|
||||||
|
# 新模式或表时将使用的默认字符集
|
||||||
|
character-set-server=utf8mb4
|
||||||
|
# 默认存储引擎
|
||||||
|
default-storage-engine=INNODB
|
||||||
|
# 将 SQL 模式设置为严格 - 暂时关闭
|
||||||
|
# sql-mode=
|
||||||
|
# 最大连接数
|
||||||
|
max_connections=1024
|
||||||
|
# 表缓存
|
||||||
|
table_open_cache=2000
|
||||||
|
# 表内存
|
||||||
|
tmp_table_size=16M
|
||||||
|
# 线程缓存
|
||||||
|
thread_cache_size=10
|
||||||
|
# 设置大小写不敏感
|
||||||
|
lower_case_table_names=1
|
||||||
|
|
||||||
|
# myisam设置
|
||||||
|
myisam_max_sort_file_size=100G
|
||||||
|
myisam_sort_buffer_size=8M
|
||||||
|
key_buffer_size=8M
|
||||||
|
read_buffer_size=0
|
||||||
|
read_rnd_buffer_size=0
|
||||||
|
|
||||||
|
# innodb设置
|
||||||
|
innodb_flush_log_at_trx_commit=1
|
||||||
|
innodb_log_buffer_size=1M
|
||||||
|
innodb_buffer_pool_size=8M
|
||||||
|
innodb_log_file_size=48M
|
||||||
|
innodb_thread_concurrency=33
|
||||||
|
innodb_autoextend_increment=64
|
||||||
|
innodb_buffer_pool_instances=8
|
||||||
|
innodb_concurrency_tickets=5000
|
||||||
|
innodb_old_blocks_time=1000
|
||||||
|
innodb_open_files=300
|
||||||
|
innodb_stats_on_metadata=0
|
||||||
|
innodb_file_per_table=1
|
||||||
|
innodb_checksum_algorithm=0
|
||||||
|
# 其他设置
|
||||||
|
back_log=80
|
||||||
|
flush_time=0
|
||||||
|
join_buffer_size=256K
|
||||||
|
max_allowed_packet=4M
|
||||||
|
max_connect_errors=100
|
||||||
|
open_files_limit=4161
|
||||||
|
sort_buffer_size=256K
|
||||||
|
table_definition_cache=1400
|
||||||
|
binlog_row_event_max_size=8K
|
||||||
|
sync_master_info=10000
|
||||||
|
sync_relay_log=10000
|
||||||
|
sync_relay_log_info=10000
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
docker run -d --name xxl-mysql \
|
||||||
|
--privileged=true \
|
||||||
|
--network xxl-network \
|
||||||
|
-v ./log:/var/log/mysql \
|
||||||
|
-v ./data:/var/lib/mysql \
|
||||||
|
-v ./config/my.cnf:/etc/my.cnf \
|
||||||
|
-e MYSQL_ROOT_PASSWORD=root \
|
||||||
|
mysql:8.4.1
|
|
@ -0,0 +1,13 @@
|
||||||
|
1、 下载这两个文件
|
||||||
|
mysql-8.4.1: https://kdocs.cn/l/chQxllwDbv1T
|
||||||
|
xxl-job-admin-2.4.1: https://kdocs.cn/l/cvwthMg4JpPF
|
||||||
|
2、 加载镜像
|
||||||
|
文件下载下来之后使用{docker load < [文件]}这个命令进行加载到docker当中
|
||||||
|
3、执行网络脚本
|
||||||
|
xxl-net.sh脚本执行,执行脚本可以添加IP范围
|
||||||
|
4、执行镜像脚本
|
||||||
|
如果想要IP固定可以添加`--ip`进行ip的设定
|
||||||
|
· 先执行depXXLMysql.sh脚本
|
||||||
|
· 再执行depXXLAdmin.sh脚本
|
||||||
|
5、hosts配置
|
||||||
|
在host当中配置xxl-job-admin的IP和端口
|
|
@ -0,0 +1 @@
|
||||||
|
docker network create xxl-network
|
Loading…
Reference in New Issue