Commit 9b17616f by BetterXT

add xxl job and config

add tou tiao api client
parents
HELP.md
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
plugins {
id 'org.springframework.boot' version '1.5.18.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'io.better'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenLocal()
maven {
url "https://repo.spring.io/milestone"
}
maven {
url 'https://maven.aliyun.com/repository/spring'
}
maven {
url 'https://maven.aliyun.com/repository/public'
}
mavenCentral()
}
ext {
set('springCloudVersion', 'Edgware.SR5')
}
dependencies {
compile 'com.xuxueli:xxl-job-core:2.0.2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'toutiao-api'
package io.better.toutiao;
import feign.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
/**
* The type Tou tiao api application.
*/
@SpringBootApplication
@EnableFeignClients
public class TouTiaoApiApplication {
/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(String[] args) {
SpringApplication.run(TouTiaoApiApplication.class, args);
}
@Bean
Logger.Level feignLevel() {
return Logger.Level.FULL;
}
}
package io.better.toutiao.api;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* The interface Advertiser api.
*
* @author better create in 2019-04-27 10:47
*/
@FeignClient(name = "${toutiao.api.advertiser-url}", url = "/advertiser")
public interface AdvertiserApi {
/**
* 获取广告主信息
*
* @param accessToken accessToken
* @param advertiserIds 广告主ID数组
* @param fields 字段数组
* @return the advertiser info
*/
@GetMapping(value = "/info")
List<Map<String, Object>> getAdvertiserInfo(@RequestHeader("Access-Token") String accessToken,
@RequestParam("advertiser_ids") Integer[] advertiserIds,
@RequestParam("fields") String[] fields);
/**
* 获取广告主资质信息
*
* @param accessToken 访问凭证
* @param advertiserId 广告主id
* @return advertiser qualification
*/
@GetMapping(value = "qualification/get/")
List<Object> getAdvertiserQualification(@RequestHeader("Access-Token") String accessToken, @RequestParam("advertiser_id") Integer advertiserId);
/**
* 提交广告主资质信息
*
* @param accessToken 访问凭证
* @param subject 主体信息
* @param others 开户资质列表
* @param promotion 推广资质
* @return list
*/
@PostMapping(value = "qualification/submit/")
List<Object> submitAdvertiserQualification(@RequestHeader("Access-Token") String accessToken,
@RequestBody Object subject,
@RequestBody Object[] others,
@RequestBody Object promotion);
}
package io.better.toutiao.api;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* The interface Agent api.
*
* @author better create in 2019-04-27 11:17
*/
@FeignClient(name = "${toutiao.api.advertiser-url}", url = "/agent/advertiser")
public interface AgentApi {
/**
* 获取代理商下的广告主ID列表
*
* @param accessToken 访问凭证
* @param agentId 代理商ID
* @param page 当前页
* @param pageSize 每页记录数
* @return advertiser by agent id
*/
@GetMapping(value = "/select")
List<Object> getAdvertiserByAgentId(@RequestHeader("Access-Token") String accessToken,
@RequestParam("advertiser_id") Integer agentId,
@RequestParam(value = "page", defaultValue = "1") String page,
@RequestParam(value = "page_size", defaultValue = "100") String pageSize);
/**
* 代理商创建广告主信息
*
* @param accessToken 访问凭证
* @param object 创建信息
* @return the list
*/
@PostMapping(value = "/create")
List<Object> createAdvertiserByAgent(@RequestHeader("Access-Token") String accessToken,
@RequestBody Object object);
/**
* 代理商更新广告主信息
*
* @param accessToken 访问凭证
* @param object 更新信息
* @return the list
*/
@PostMapping(value = "/update")
List<Object> updateAdvertiserByAgent(@RequestHeader("Access-Token") String accessToken,
@RequestBody Object object);
}
package io.better.toutiao.api;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
/**
* @author better create in 2019-04-27 10:26
*/
@FeignClient(value = "${toutiao.api.oauth-url}", url = "/oauth2")
public interface OAuth2Api {
/**
* 根据appId,secret等信息获取access_token
*
* @param params 请求参数
* @return
*/
@PostMapping(value = "/access_token")
Object getAccessToken(@RequestBody Map<String, Object> params);
/**
* 通过refresh_token刷新access_token和refresh_token
*
* @param params 请求参数
* @return
*/
@PostMapping(value = "/refresh_token")
Map<String, Object> refreshToken(@RequestBody Map<String, Object> params);
}
package io.better.toutiao.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import io.better.toutiao.properties.XxlJobProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* The type Xxl job config.
*
* @author better create in 2019-04-28 10:27
*/
@Configuration
public class XxlJobConfig {
/**
* Xxl job executor xxl job spring executor.
*
* @param xxlJobProperties the xxl job properties
* @return the xxl job spring executor
*/
@Bean(initMethod = "start", destroyMethod = "destroy")
@ConditionalOnMissingBean(value = XxlJobSpringExecutor.class)
public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties) {
XxlJobSpringExecutor xxlJobExecutor = new XxlJobSpringExecutor();
xxlJobExecutor.setIp(xxlJobProperties.getIp());
xxlJobExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
xxlJobExecutor.setPort(xxlJobProperties.getPort());
xxlJobExecutor.setLogPath(xxlJobProperties.getLogPath());
xxlJobExecutor.setAppName(xxlJobProperties.getAppName());
xxlJobExecutor.setAccessToken(xxlJobProperties.getAccessToken());
xxlJobExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
return xxlJobExecutor;
}
}
package io.better.toutiao.job.datareport;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 广告主信息获取定时任务
*
* @author better create in 2019-04-28 11:04
*/
@JobHandler(value = "AdvertisersInfoXxlJob")
@Component
@Slf4j
public class AdvertisersInfoXxlJob extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
return null;
}
}
package io.better.toutiao.job.datareport;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 广告创意信息定时获取任务
*
* @author better create in 2019-04-28 11:07
*/
@JobHandler(value = "AdvertisingCreativeInfoXxlJob")
@Component
@Slf4j
public class AdvertisingCreativeInfoXxlJob extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
return null;
}
}
package io.better.toutiao.job.datareport;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 广告组信息定时获取任务
*
* @author better create in 2019-04-28 11:06
*/
@JobHandler(value = "AdvertisersGroupInfoXxlJob")
@Component
@Slf4j
public class AdvertisingGroupInfoXxlJob extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
return null;
}
}
package io.better.toutiao.job.datareport;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 广告计划信息定时获取任务
*
* @author better create in 2019-04-28 11:07
*/
@JobHandler(value = "AdvertisingPlanInfoXxlJob")
@Component
@Slf4j
public class AdvertisingPlanInfoXxlJob extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
return null;
}
}
package io.better.toutiao.job.oauth;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import io.better.toutiao.api.OAuth2Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author better create in 2019-04-28 10:26
*/
@Component
@JobHandler(value = "AccessTokenRefreshXxlJob")
@Slf4j
public class AccessTokenRefreshXxlJob extends IJobHandler {
private OAuth2Api oAuth2Api;
@Autowired
public AccessTokenRefreshXxlJob(OAuth2Api oAuth2Api) {
this.oAuth2Api = oAuth2Api;
}
@Override
public ReturnT<String> execute(String param) throws Exception {
log.info("AccessTokenRefreshXxlJob is execute and param => {}", param);
oAuth2Api.refreshToken(null);
return ReturnT.SUCCESS;
}
}
package io.better.toutiao.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author better create in 2019-04-28 10:27
*/
@ConfigurationProperties(prefix = "xxl.job")
@Component
@Data
public class XxlJobProperties {
/**
* xxl-job地址
*/
private String adminAddresses;
/**
* IP地址
*/
private String ip;
/**
* 日志名称
*/
private String appName;
/**
* 日志地址
*/
private String logPath;
/**
* 端口号
*/
private Integer port;
/**
* 凭证
*/
private String accessToken;
/**
* 日志保存时长
*/
private Integer logRetentionDays;
}
toutiao:
api:
advertiser-url: ad.toutiao.com/open_api/2
oauth-url: https://ad.toutiao.com/open_api
server:
port: 9004
spring:
datasource:
url: jdbc:mysql://localhost:3306/toutiao
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
logging:
level:
feign=debug
xxl:
job:
admin-addresses: http://127.0.0.1:9001/xxl-job-admin
ip: 127.0.0.1
app-name: toutiao-api-job
port: 9003
log-path: Users/better/data/applogs/xxl-job/jobhandler
access-token:
log-retention-days: 1
package io.better.toutiao.api;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TouTiaoApiApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment