feat: initial iShare project code

This commit is contained in:
purovps
2026-02-16 23:20:59 +08:00
parent 8c83a6fd46
commit 6f270a972e
1910 changed files with 218015 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common</artifactId>
<version>5.2.0</version>
</parent>
<artifactId>pigx-common-job</artifactId>
<packaging>jar</packaging>
<description>pigx 定时任务</description>
<dependencies>
<!--xxl job-->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>${xxl.job.version}</version>
</dependency>
<!--提供服务发现能力-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,71 @@
package com.pig4cloud.pigx.common.job;
import com.pig4cloud.pigx.common.job.properties.XxlExecutorProperties;
import com.pig4cloud.pigx.common.job.properties.XxlJobProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.util.stream.Collectors;
/**
* xxl-job自动装配
*
* @author lishangbu
* @date 2020/9/14
*/
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
@EnableConfigurationProperties(XxlJobProperties.class)
public class XxlJobAutoConfiguration {
/**
* 服务名称 包含 XXL_JOB_ADMIN 则说明是 Admin
*/
private static final String XXL_JOB_ADMIN = "xxl-job-admin";
/**
* 配置xxl-job 执行器,提供自动发现 xxl-job-admin 能力
* @param xxlJobProperties xxl 配置
* @param discoveryClient 注册发现客户端
* @return
*/
@Bean
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties, Environment environment,
DiscoveryClient discoveryClient) {
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
XxlExecutorProperties executor = xxlJobProperties.getExecutor();
// 应用名默认为服务名
String appName = executor.getAppname();
if (!StringUtils.hasText(appName)) {
appName = environment.getProperty("spring.application.name");
}
xxlJobSpringExecutor.setAppname(appName);
xxlJobSpringExecutor.setAddress(executor.getAddress());
xxlJobSpringExecutor.setIp(executor.getIp());
xxlJobSpringExecutor.setPort(executor.getPort());
xxlJobSpringExecutor.setAccessToken(executor.getAccessToken());
xxlJobSpringExecutor.setLogPath(executor.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(executor.getLogRetentionDays());
// 如果配置为空则获取注册中心的服务列表 "http://pigx-xxl:9080/xxl-job-admin"
if (!StringUtils.hasText(xxlJobProperties.getAdmin().getAddresses())) {
String serverList = discoveryClient.getServices().stream().filter(s -> s.contains(XXL_JOB_ADMIN))
.flatMap(s -> discoveryClient.getInstances(s).stream()).map(instance -> String
.format("http://%s:%s/%s", instance.getHost(), instance.getPort(), XXL_JOB_ADMIN))
.collect(Collectors.joining(","));
xxlJobSpringExecutor.setAdminAddresses(serverList);
}
else {
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdmin().getAddresses());
}
return xxlJobSpringExecutor;
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.job.annotation;
import com.pig4cloud.pigx.common.job.XxlJobAutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author lengleng
* @date 2019-09-18
* <p>
* 开启支持XXL
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({ XxlJobAutoConfiguration.class })
public @interface EnablePigxXxlJob {
}

View File

@@ -0,0 +1,19 @@
package com.pig4cloud.pigx.common.job.properties;
import lombok.Data;
/**
* xxl-job管理平台配置
*
* @author lishangbu
* @date 2020/9/14
*/
@Data
public class XxlAdminProperties {
/**
* 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。 执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
*/
private String addresses;
}

View File

@@ -0,0 +1,50 @@
package com.pig4cloud.pigx.common.job.properties;
import lombok.Data;
/**
* xxl-job执行器配置
*
* @author lishangbu
* @date 2020/9/14
*/
@Data
public class XxlExecutorProperties {
/**
* 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
*/
private String appname;
/**
* 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题
*/
private String address;
/**
* 执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP 该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和
* "调度中心请求并触发任务"
*/
private String ip;
/**
* 执行器端口号 [选填]小于等于0则自动获取默认端口为9099单机部署多个执行器时注意要配置不同执行器端口
*/
private Integer port = 9099;
/**
* 执行器通讯TOKEN [选填]:非空时启用;
*/
private String accessToken;
/**
* 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
*/
private String logPath = "logs/applogs/xxl-job/jobhandler";
/**
* 执行器日志保存天数 [选填] 值大于3时生效启用执行器Log文件定期清理功能否则不生效
*/
private Integer logRetentionDays = 30;
}

View File

@@ -0,0 +1,23 @@
package com.pig4cloud.pigx.common.job.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* xxl-job配置
*
* @author lishangbu
* @date 2020/9/14
*/
@Data
@ConfigurationProperties(prefix = "xxl.job")
public class XxlJobProperties {
@NestedConfigurationProperty
private XxlAdminProperties admin = new XxlAdminProperties();
@NestedConfigurationProperty
private XxlExecutorProperties executor = new XxlExecutorProperties();
}