提交 df791681 authored 作者: 黄承天's avatar 黄承天

Initial commit

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
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
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
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
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>sqlserver-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sqlserver-test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>2.8.3</version>
</dependency>
<!--mysql 用于实际环境 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.sqlserver.collector;
import com.example.sqlserver.collector.entity.local.Article;
import com.example.sqlserver.collector.repository.local.AnnexRepository;
import com.example.sqlserver.collector.repository.local.ArticleRepository;
import com.example.sqlserver.collector.repository.local.ChannelRepository;
import com.example.sqlserver.collector.repository.remote.RemoteArticleInfoRepository;
import com.example.sqlserver.collector.repository.remote.RemoteArticleRepository;
import com.example.sqlserver.collector.repository.remote.RemoteChannelRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import sun.util.resources.ga.LocaleNames_ga;
import java.util.Comparator;
/**
* @author C
*/
@Slf4j
@EnableScheduling
@SpringBootApplication
public class SqlserverTestApplication implements CommandLineRunner {
@Autowired
RemoteArticleRepository remoteArticleRepository;
@Autowired
RemoteArticleInfoRepository remoteArticleInfoRepository;
@Autowired
RemoteChannelRepository remoteChannelRepository;
@Autowired
ArticleRepository articleRepository;
@Autowired
AnnexRepository annexRepository;
@Autowired
ChannelRepository channelRepository;
public static void main(String[] args) {
SpringApplication.run(SqlserverTestApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
long lmgl = remoteChannelRepository.count();
long xxgl_lm = remoteArticleInfoRepository.count();
long xxgl = remoteArticleRepository.count();
long total = xxgl + xxgl_lm + lmgl;
System.out.println("xxgl : " + xxgl);
System.out.println("xxgl_lm : " + xxgl_lm);
System.out.println("lmgl : " + lmgl);
System.out.println("total : " + total);
}
}
package com.example.sqlserver.collector.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
/**
* @author C
*/
@ComponentScan
@Configuration
public class DataSourceConfig {
/**
* 本地数据源 MySQL
* 用于存储和提供
* 数据仓库
*/
@Bean(name = "localDataSource")
@Qualifier("localDataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource.local")
public DataSource localDataSource() {
return DataSourceBuilder.create().build();
}
/**
* 对方数据源
* SQL Server 2008
* 用于采集
*/
@Bean(name = "remoteDataSource")
@Qualifier("remoteDataSource")
@ConfigurationProperties(prefix = "spring.datasource.remote")
public DataSource remoteDataSource() {
return DataSourceBuilder.create().build();
}
}
package com.example.sqlserver.collector.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import java.util.Map;
/**
* @author C
*/
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactoryLocation",
transactionManagerRef = "transactionManagerLocation",
basePackages = {
"com.example.sqlserver.collector.repository.local"
}
)
@EnableConfigurationProperties(JpaProperties.class)
public class LocationConfig {
@Autowired
@Qualifier("localDataSource")
private DataSource locationDataSource;
@Primary
@Bean(name = "entityManageLocation")
public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
return entityManagerFactoryLocation(builder).getObject().createEntityManager();
}
@Primary
@Bean(name = "entityManagerFactoryLocation")
public LocalContainerEntityManagerFactoryBean entityManagerFactoryLocation(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(locationDataSource)
.properties(getVendorProperties(locationDataSource))
.packages(
"com.example.sqlserver.collector.entity.local"
)
.persistenceUnit("locationPersistenceUnit")
.build();
}
@Autowired
private JpaProperties jpaProperties;
private Map<String, String> getVendorProperties(DataSource dataSource) {
return jpaProperties.getHibernateProperties(dataSource);
}
@Primary
@Bean(name = "transactionManagerLocation")
public PlatformTransactionManager transactionManagerLocation(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(entityManagerFactoryLocation(builder).getObject());
}
}
package com.example.sqlserver.collector.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import java.util.Map;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactoryRemote",
transactionManagerRef = "transactionManagerRemote",
basePackages = {"com.example.sqlserver.collector.repository.remote"}
)
@EnableConfigurationProperties(JpaProperties.class)
public class RemoteConfig {
@Autowired
@Qualifier("remoteDataSource")
private DataSource remoteDataSource;
@Bean(name = "entityManageRemote")
public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
return entityManagerFactoryRemote(builder).getObject().createEntityManager();
}
@Bean(name = "entityManagerFactoryRemote")
public LocalContainerEntityManagerFactoryBean entityManagerFactoryRemote(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(remoteDataSource)
.properties(getVendorProperties(remoteDataSource))
.packages("com.example.sqlserver.collector.entity.remote")
.persistenceUnit("remotePersistenceUnit")
.build();
}
@Autowired
private JpaProperties jpaProperties;
private Map<String, String> getVendorProperties(DataSource dataSource) {
return jpaProperties.getHibernateProperties(dataSource);
}
@Bean(name = "transactionManagerRemote")
public PlatformTransactionManager transactionManagerRemote(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(entityManagerFactoryRemote(builder).getObject());
}
}
package com.example.sqlserver.collector.controller;
import com.example.sqlserver.collector.entity.local.Annex;
import com.example.sqlserver.collector.repository.local.AnnexRepository;
import com.example.sqlserver.collector.task.Tasks;
import javafx.scene.media.VideoTrack;
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 java.util.List;
import java.util.stream.Collectors;
/**
* <p>Description : sqlserver-collector
* <p>Date : 2019/8/27 15:32
* <p>@author : C
*/
@RestController
public class CollectorController {
private final
Tasks tasks;
private final
AnnexRepository annexRepository;
@Autowired
public CollectorController(Tasks tasks, AnnexRepository annexRepository) {
this.tasks = tasks;
this.annexRepository = annexRepository;
}
@GetMapping("/start")
public ResponseEntity<String> start(){
tasks.setIsRunning(true);
return new ResponseEntity<>("start successful", HttpStatus.OK);
}
@GetMapping("/close")
public ResponseEntity<String> close(){
tasks.setIsRunning(false);
return new ResponseEntity<>("close successful", HttpStatus.OK);
}
@GetMapping("/files")
public ResponseEntity<List<String>> files(){
List<String> result = annexRepository.findAll().stream()
.map(Annex::getPath)
.filter(path -> path.startsWith("file:///"))
.collect(Collectors.toList());
return new ResponseEntity<>(result , HttpStatus.OK);
}
}
package com.example.sqlserver.collector.entity.local;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.Date;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/24 14:12
* <p>@author : C
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dc_annex")
public class Annex {
@Id
@Column(name = "ANX_UUID", length = 48)
private String uuid;
@Column(name = "ANX_CREATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date createDate;
@Column(name = "ANX_UPDATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date updateDate;
@Column(name = "ANX_UUID_OLD", length = 48)
private String articleUUID;
@Column(name = "ANX_TITLE", length = 100)
private String title;
@Column(name = "ANX_PATH", length = 500)
private String path;
@Column(name = "ANX_ADS", length = 1000)
private String ads;
public Annex replacePath(String newPath) {
this.path = newPath;
return this;
}
}
package com.example.sqlserver.collector.entity.local;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.Date;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/18 14:26
* <p>@author : C
* 文章
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dc_article")
public class Article {
@Id
@Column(name = "ALE_UUID", length = 48, nullable = false)
private String uuid;
@Column(name = "ALE_CREATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date createDate;
@Column(name = "ALE_UPDATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date updateDate;
/**
* 栏目id
*/
@Column(name = "ALE_CH_UUID", length = 48)
private String chUUID;
@Column(name = "ALE_TITLE", length = 128)
private String title;
@Column(name = "ALE_FDATE", columnDefinition = "date")
private Date pubDate;
@Column(name = "ALE_ORDER_TIME", columnDefinition = "date")
private Date orderTime;
@Column(name = "ALE_EXAMINE_TIME", columnDefinition = "date")
private Date examineTime;
@Column(name = "ALE_AUTHOR", length = 100)
private String author;
/**
* 来源
*/
@Column(name = "ALE_SOURCE", length = 256)
private String source;
/**
* 摘要
*/
@Column(name = "ALE_ADS", length = 1000)
private String ads;
/**
* 关键字
*/
@Column(name = "ALE_KEYWORD", length = 500)
private String keyWord;
/**
* 类型
*/
@Column(name = "ALE_TYPE", length = 100)
private String type;
/**
* 标题图
*/
@Column(name = "ALE_PICTURE", length = 500)
private String picture;
/**
* 正文
*/
@Column(name = "ALE_CONTENT", columnDefinition = "mediumtext")
private String content;
/**
* 点击量
*/
@Column(name = "ALE_CLICK", length = 100)
private String click;
/**
* 信息置顶
*/
@Column(name = "ALE_IS_TOP", columnDefinition = "int", length = 11)
private Integer isTOP;
/**
* 来源方式
*/
@Column(name = "ALE_MODE", columnDefinition = "int", length = 11)
private Integer mode;
/**
* 浏览量
*/
@Column(name = "ALE_BROWSE", length = 100)
private String browse;
public Article replaceChUUID(String chUUID) {
this.chUUID = chUUID;
return this;
}
public Article replaceContent(String newContent) {
this.content = newContent;
return this;
}
}
package com.example.sqlserver.collector.entity.local;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.Date;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/18 14:26
* <p>@author : C
* 栏目
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dc_channel")
public class Channel {
@Id
@Column(name = "CAL_UUID", length = 48, nullable = false)
private String uuid;
@Column(name = "CAL_CREATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date createDate;
@Column(name = "CAL_UPDATE_DATE", columnDefinition = "timestamp", nullable = false)
private Date updateDate;
@Column(name = "CAL_SUPER_UUID", length = 48)
private String superUUID;
@Column(name = "CAL_NAME", length = 128)
private String name;
@Column(name = "CAL_INTRODUCE", columnDefinition = "text")
private String introduce;
@Column(name = "CAL_ORDER", columnDefinition = "int", length = 11, nullable = false)
private Integer order;
public Channel setSuperUUID(String superUUID) {
this.superUUID = superUUID;
return this;
}
public Channel replaceSuperUUID(String uuid) {
this.superUUID = superUUID;
return this;
}
}
package com.example.sqlserver.collector.entity.remote;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 14:33
* <p>@author : C
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dbo.xxgl")
public class RemoteArticle {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "bt")
private String title;
/**
* 内容
*/
@Column(name = "nr")
private String content;
/**
* 摘要
*/
@Column(name = "zy")
private String ads;
/**
* 来源
*/
@Column(name = "ly")
private String source;
@Column(name = "zz")
private String author;
@Column(name = "gjz")
private String keyWord;
}
package com.example.sqlserver.collector.entity.remote;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 14:50
* <p>@author : C
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dbo.xxgl_lm")
public class RemoteArticleInfo {
@Id
@Column(name = "xxid")
private Integer id;
/**
* 栏目编号
*/
@Column(name = "lmbh")
private String chId;
/**
* 点击量
*/
@Column(name = "djs")
private Integer click;
/**
* 提交时间
*/
@Column(name = "tjsj")
private Date orderTime;
/**
* 审核时间
*/
@Column(name = "shsj")
private Date examineTime;
/**
* 生成静态页面时间
*/
@Column(name = "scjtymsj")
private Date pubTime;
/**
* 类型:图文 文章
*/
@Column(name = "sfscjtym")
private Integer type;
/**
* 来源方式(0是转载 1是撰写)
*/
@Column(name = "lyfs")
private Integer catchMode;
/**
* 信息置顶
*/
@Column(name = "xxzd")
private Integer onTop;
}
package com.example.sqlserver.collector.entity.remote;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 16:27
* <p>@author : C
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "dbo.lmgl")
public class RemoteChannel {
/**
* 主键
*/
@Id
@Column(name = "lmbh")
private String id;
/**
* 所属站点id
*/
@Column(name = "sszd")
private String siteId;
/**
* 上级id
*/
@Column(name = "parent")
private String parentId;
/**
* 栏目名称
*/
@Column(name = "lmmc")
private String name;
/**
* 栏目简称
*/
@Column(name = "lmjc")
private String introduce;
/**
* 栏目排序
*/
@Column(name = "lmpx")
private Integer order;
}
package com.example.sqlserver.collector.entity.to;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
/**
* <p>Description : sqlserver-collector
* <p>Date : 2019/8/29 14:13
* <p>@author : C
*/
public class ChannelTo {
private String uuid;
private Date createDate;
private Date updateDate;
private String superUUID;
private String name;
private String introduce;
private Integer order;
}
package com.example.sqlserver.collector.repository.local;
import com.example.sqlserver.collector.entity.local.Annex;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/8/1 16:36
* <p>@author : C
*/
@Repository
public interface AnnexRepository extends JpaRepository<Annex, String> {
}
package com.example.sqlserver.collector.repository.local;
import com.example.sqlserver.collector.entity.local.Article;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/8/1 16:35
* <p>@author : C
*/
@Repository
public interface ArticleRepository extends JpaRepository<Article, String> {
}
package com.example.sqlserver.collector.repository.local;
import com.example.sqlserver.collector.entity.local.Channel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/8/1 16:38
* <p>@author : C
*/
@Repository
public interface ChannelRepository extends JpaRepository<Channel, String> {
}
package com.example.sqlserver.collector.repository.remote;
import com.example.sqlserver.collector.entity.remote.RemoteArticleInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 16:21
* <p>@author : C
*/
@Repository
public interface RemoteArticleInfoRepository extends JpaRepository<RemoteArticleInfo,Integer> {
List<RemoteArticleInfo> findAllByChId(String chId);
}
package com.example.sqlserver.collector.repository.remote;
import com.example.sqlserver.collector.entity.remote.RemoteArticle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 14:59
* <p>@author : C
*/
@Repository
public interface RemoteArticleRepository extends JpaRepository<RemoteArticle, Integer> {
}
package com.example.sqlserver.collector.repository.remote;
import com.example.sqlserver.collector.entity.remote.RemoteChannel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/15 16:33
* <p>@author : C
*/
@Repository
public interface RemoteChannelRepository extends JpaRepository<RemoteChannel,String> {
}
package com.example.sqlserver.collector.service;
import com.example.sqlserver.collector.entity.local.Article;
import com.example.sqlserver.collector.entity.local.Annex;
import com.example.sqlserver.collector.entity.local.Channel;
import com.example.sqlserver.collector.entity.remote.RemoteArticle;
import com.example.sqlserver.collector.entity.remote.RemoteArticleInfo;
import com.example.sqlserver.collector.entity.remote.RemoteChannel;
import com.example.sqlserver.collector.repository.local.ArticleRepository;
import com.example.sqlserver.collector.repository.local.AnnexRepository;
import com.example.sqlserver.collector.repository.local.ChannelRepository;
import com.example.sqlserver.collector.repository.remote.RemoteArticleInfoRepository;
import com.example.sqlserver.collector.repository.remote.RemoteArticleRepository;
import com.example.sqlserver.collector.repository.remote.RemoteChannelRepository;
import com.example.sqlserver.collector.service.helper.ContentParseHelper;
import com.example.sqlserver.collector.service.helper.TransHelper;
import com.example.sqlserver.collector.utils.OssUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/26 14:08
* <p>@author : C
*/
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Slf4j
@Service
public class Updater {
@Autowired
RemoteArticleRepository remoteArticleRepository;
@Autowired
RemoteArticleInfoRepository remoteArticleInfoRepository;
@Autowired
RemoteChannelRepository remoteChannelRepository;
@Autowired
ArticleRepository articleRepository;
@Autowired
AnnexRepository annexRepository;
@Autowired
ChannelRepository channelRepository;
@Autowired
TransHelper transHelper;
@Autowired
ContentParseHelper contentParseHelper;
@Autowired
OssUtil ossUtil;
@Value("${oss.bucket}")
String bucket;
/**
* 待更新文章队列
*/
private List<RemoteArticle> remoteArticleList = Lists.newArrayList();
/**
* 待更新栏目队列
*/
private List<RemoteChannel> remoteChannelList = Lists.newArrayList();
/**
* 待更新附件路径队列
*/
private List<String> pathList = Lists.newArrayList();
private Map<Channel, List<Channel>> channelSubMap = Maps.newHashMap();
Map<Channel, List<Channel>> channelArticleMap = Maps.newHashMap();
private Integer channelCount = 0;
private Integer articleCount = 0;
private Integer annexCount = 0;
private Set<String> savedChannelIds = Sets.newHashSet();
public void updateAll() {
log.info("开始采集数据...");
log.info("[栏目信息]待更新数据总条数 : {}", remoteChannelRepository.count());
log.info("[文章信息]待更新数据总条数 : {}", remoteArticleInfoRepository.count());
remoteChannelList = remoteChannelRepository.findAll();
remoteChannelList.forEach(this::updateHandle);
}
public void updateHandle(RemoteChannel remoteChannel) {
String id = remoteChannel.getId();
Channel keyChannel = transHelper.toChannel(remoteChannel);
if (isNew(remoteChannel)){
List<Channel> channelsForSave = remoteChannelList.stream()
.filter(remoteChannel1 -> isSub(remoteChannel1, id))
.map(transHelper::toChannel)
.map(channel -> channel.replaceSuperUUID(keyChannel.getUuid()))
.collect(Collectors.toList());
savedChannelIds.add(id);
savedChannelIds.addAll(remoteChannelList.stream()
.filter(remoteChannel1 -> isSub(remoteChannel1, id))
.map(RemoteChannel::getId)
.collect(Collectors.toList())
);
save(keyChannel);
saveChannels(channelsForSave);
channelCount++;
channelCount += channelsForSave.size();
log.info("[栏目信息]已保存 : {}", channelCount);
}
List<Article> articlesForSave = remoteArticleInfoRepository.findAllByChId(id).stream()
.map(transHelper::toArticle)
.map(article -> article.replaceChUUID(keyChannel.getUuid()))
.map(transHelper::replaceContent)
.collect(Collectors.toList());
saveArticles(articlesForSave);
articleCount += articlesForSave.size();
log.info("[文章信息]已保存 : {}", articleCount);
List<Annex> annexesForSave = articlesForSave.stream()
.flatMap(transHelper::toAnnexStream)
.filter(contentParseHelper::isFile)
.collect(Collectors.toList());
saveAnnexes(annexesForSave);
annexCount += annexesForSave.size();
log.info("[附件信息]已保存 : {}", annexCount);
}
private Boolean isNew(RemoteChannel remoteChannel) {
return savedChannelIds.stream().noneMatch(id -> Objects.equals(remoteChannel.getId(), id));
}
private Boolean isSub(RemoteChannel remoteChannel, String id) {
return remoteChannel.getId().length() > id.length() && remoteChannel.getId().startsWith(id);
}
private Stream<RemoteArticleInfo> getArticleInfoStream(String id) {
return remoteArticleInfoRepository.findAllByChId(id).stream();
}
public void getRemoteArticlesForSave() {
if (remoteArticleList.isEmpty()) {
List<RemoteArticle> remoteArticlesForSave = remoteArticleRepository.findAll();
remoteArticleList.addAll(remoteArticlesForSave);
log.info("获取文章队列完毕 需要更新数量剩余 : {} ", remoteArticleList.size());
}
}
public void getRemoteChannelsForSave() {
if (remoteChannelList.isEmpty()) {
List<RemoteChannel> remoteChannelsForSave = remoteChannelRepository.findAll();
remoteChannelList.addAll(remoteChannelsForSave);
log.info("获取栏目队列完毕 需要更新数量剩余 : {} ", remoteChannelsForSave.size());
}
}
/**
* @param n 一次从待更新集合中取多少条
*/
public void updateChannels(Integer n) {
List<RemoteChannel> remoteChannelListForSave = remoteChannelList.stream()
.limit(n)
.collect(Collectors.toList());
remoteChannelList.removeAll(remoteChannelListForSave);
List<Channel> channelList = remoteChannelListForSave.stream()
.map(transHelper::toChannel)
.collect(Collectors.toList());
channelList.forEach(this::save);
if (!remoteChannelList.isEmpty()) {
log.info("栏目待更新数量 : {} ", remoteChannelList.size());
}
}
/**
* @param n 一次从待更新集合中取多少条
*/
public void updateArticlesAndAnnexes(Integer n) {
List<RemoteArticle> remoteArticleListForSave = remoteArticleList.stream()
.limit(n)
.collect(Collectors.toList());
List<Article> articleList = remoteArticleListForSave.stream()
.filter(transHelper::infoExists)
.map(transHelper::toArticle)
.map(transHelper::replaceContent)
.map(articleRepository::save)
.collect(Collectors.toList());
remoteArticleList.removeAll(remoteArticleListForSave);
List<Annex> annexList = articleList.stream()
.flatMap(transHelper::toAnnexStream)
.filter(contentParseHelper::isFile)
.collect(Collectors.toList());
List<String> pathsForUpload = articleList.stream()
.flatMap(transHelper::toPathStream)
.map(contentParseHelper::restorePath)
.collect(Collectors.toList());
pathList.addAll(pathsForUpload);
if (!annexList.isEmpty()) {
log.info("本次文章更新带有附件数量 : {}", annexList.size());
}
annexList.forEach(this::save);
if (!remoteArticleList.isEmpty()) {
log.info("文章待更新数量 : {}", remoteArticleList.size());
}
}
/**
* @param n 一次从待更新集合中取多少条
*/
public void update(Integer n) {
List<RemoteChannel> remoteChannelListForSave = remoteChannelList.stream()
.limit(n)
.collect(Collectors.toList());
List<Channel> channelList = remoteChannelListForSave.stream()
.map(transHelper::toChannel)
.map(channelRepository::save)
.collect(Collectors.toList());
remoteChannelList.removeAll(remoteChannelListForSave);
if (!remoteChannelList.isEmpty()) {
log.info("栏目待更新数量 : {} ", remoteChannelList.size());
}
List<RemoteArticle> remoteArticleListForSave = new ArrayList<>(remoteArticleList);
List<Article> articleList = remoteArticleListForSave.stream()
.filter(transHelper::infoExists)
.map(transHelper::toArticle)
.map(transHelper::replaceContent)
.map(articleRepository::save)
.collect(Collectors.toList());
remoteArticleList.removeAll(remoteArticleListForSave);
List<Annex> annexList = articleList.stream()
.flatMap(transHelper::toAnnexStream)
.filter(contentParseHelper::isFile)
.collect(Collectors.toList());
List<String> pathsForUpload = articleList.stream()
.flatMap(transHelper::toPathStream)
.map(contentParseHelper::restorePath)
.collect(Collectors.toList());
pathList.addAll(pathsForUpload);
if (!annexList.isEmpty()) {
log.info("本次文章更新带有附件数量 : {}", annexList.size());
}
annexList.forEach(this::save);
if (!remoteArticleList.isEmpty()) {
log.info("文章待更新数量 : {}", remoteArticleList.size());
}
}
/**
* @param n 一次从待更新集合中取多少条
*/
public void uploadFile(Integer n) {
List<String> filesForUpload = pathList.stream()
.limit(n)
.collect(Collectors.toList());
filesForUpload.forEach(this::upload);
}
private void save(Channel channel) {
channelRepository.save(channel);
}
private void saveChannels(List<Channel> channels) {
channelRepository.save(channels);
}
private void save(Article article) {
articleRepository.save(article);
}
private void saveArticles(List<Article> articles) {
articleRepository.save(articles);
}
private void save(Annex annex) {
annexRepository.save(annex);
}
private void saveAnnexes(List<Annex> annexes) {
annexRepository.save(annexes);
}
private void upload(String path) {
try {
InputStream inputStream = Files.newInputStream(Paths.get(System.getProperty("user.dir") + path), StandardOpenOption.READ);
ossUtil.uploadFile(bucket, transHelper.getFileName(path), inputStream);
log.info("文件上传完毕 路径 : {} ", path);
} catch (IOException e) {
log.error("文件上传失败 路径 : {} 异常 : {}", path, e);
}
}
}
package com.example.sqlserver.collector.service.helper;
import com.example.sqlserver.collector.entity.local.Annex;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/23 9:53
* <p>@author : C
*/
@SuppressWarnings({"Duplicates", "SpringAutowiredFieldsWarningInspection"})
@Service
public class ContentParseHelper {
@Value("${oss.prefix}")
String prefix;
@Autowired
ContentParseHelper contentParseHelper;
public List<String> parseSrcPathsFromContent(String content) {
List<String> result = Lists.newArrayList();
int index = 0;
while (index < content.length()) {
int start = content.indexOf("src=\"", index);
if (start > 0) {
index = start + 1;
int firstQuote = content.indexOf("\"", start);
int secondQuote = content.indexOf("\"", firstQuote + 1);
String firstResult = content.substring(start, secondQuote + 1);
firstQuote = firstResult.indexOf("\"");
secondQuote = firstResult.indexOf("\"", firstQuote + 1);
result.add(firstResult.substring(firstQuote + 1, secondQuote));
} else {
break;
}
}
return result;
}
public List<String> parseHrefPathsFromContent(String content) {
List<String> result = Lists.newArrayList();
int index = 0;
while (index < content.length()) {
int start = content.indexOf("href=\"", index);
if (start > 0) {
index = start + 1;
int firstQuote = content.indexOf("\"", start);
int secondQuote = content.indexOf("\"", firstQuote + 1);
String firstResult = content.substring(start, secondQuote + 1);
firstQuote = firstResult.indexOf("\"");
secondQuote = firstResult.indexOf("\"", firstQuote + 1);
result.add(firstResult.substring(firstQuote + 1, secondQuote));
} else {
break;
}
}
return result;
}
public String parseTitlePicFromContent(String content) {
List<String> results = parseSrcPathsFromContent(content);
String result = "";
if (!results.isEmpty()) {
if (contentParseHelper.pathIsPic(results.get(0))) {
result = results.get(0);
}
}
return result;
}
public List<String> getPaths(String content) {
List<String> srcPaths = parseSrcPathsFromContent(content);
List<String> hrefPaths = parseHrefPathsFromContent(content);
List<String> paths = Lists.newArrayList();
paths.addAll(srcPaths);
paths.addAll(hrefPaths);
return paths;
}
public String replacePaths(String content) {
String newContent = content;
List<String> paths = getPaths(content);
for (String path : paths) {
if (pathIsFile(path) && path.startsWith("/")) {
newContent = newContent.replace(path, replacePath(path));
}
}
return newContent;
}
public String replaceRepeatedPaths(String content) {
String newContent = content;
List<String> paths = getPaths(content);
for (String path : paths) {
if (path.startsWith(prefix + prefix)) {
newContent = newContent.replaceAll(prefix + prefix, prefix);
}
}
return newContent;
}
public Boolean isFile(Annex annex) {
return pathIsFile(annex.getPath());
}
public Boolean isPic(Annex annex) {
return pathIsPic(annex.getPath());
}
public Boolean pathIsFile(String path) {
int formatIndex = path.lastIndexOf(".");
if (formatIndex > 0) {
String format = path.substring(formatIndex);
return Objects.equals(".jpg", format) ||
Objects.equals(".png", format) ||
Objects.equals(".bmp", format) ||
Objects.equals(".xls", format) ||
Objects.equals(".doc", format) ||
Objects.equals(".gif", format) ||
Objects.equals(".pdf", format);
}
return false;
}
public Boolean pathIsPic(String path) {
int formatIndex = path.lastIndexOf(".");
if (formatIndex > 0) {
String format = path.substring(formatIndex);
return Objects.equals(".jpg", format) ||
Objects.equals(".png", format) ||
Objects.equals(".bmp", format);
}
return false;
}
public String replacePath(String path) {
if (path.startsWith(prefix)) {
return path;
} else {
return prefix + path;
}
}
public String restorePath(String path) {
if (path.startsWith(prefix)) {
return path.substring(prefix.length());
} else {
return path;
}
}
public int kmp(String source, String target) {
char[] sourceArr = source.toCharArray();
char[] targetArr = target.toCharArray();
int[] fixTable = getFixTable(target);
int index = 0;
while (index < sourceArr.length - targetArr.length) {
boolean match = true;
for (int i = 0; i < targetArr.length; i++) {
if (sourceArr[i + index] != targetArr[i]) {
match = false;
index = index + i - fixTable[i];
break;
}
}
if (match) {
return index;
}
}
return -1;
}
private int[] getFixTable(String target) {
int size = target.length();
int[] fixTable = new int[size];
for (int i = 0; i < fixTable.length; i++) {
if (i == 0) {
fixTable[i] = -1;
} else if (i == 1) {
fixTable[i] = 0;
} else {
int fixLength = 0;
//a b a b c
for (int j = 0; j < i - 1; j++) {
if (Objects.equals(target.substring(0, j + 1), target.substring(i - j - 1, i))) {
fixLength = j + 1;
}
}
fixTable[i] = fixLength;
}
}
return fixTable;
}
}
package com.example.sqlserver.collector.service.helper;
import com.example.sqlserver.collector.entity.local.Article;
import com.example.sqlserver.collector.entity.local.Annex;
import com.example.sqlserver.collector.entity.local.Channel;
import com.example.sqlserver.collector.entity.remote.RemoteArticle;
import com.example.sqlserver.collector.entity.remote.RemoteArticleInfo;
import com.example.sqlserver.collector.entity.remote.RemoteChannel;
import com.example.sqlserver.collector.repository.remote.RemoteArticleInfoRepository;
import com.example.sqlserver.collector.repository.remote.RemoteArticleRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* <p>Description : sqlserver-test
* <p>Date : 2019/7/18 14:15
* <p>@author : C
*/
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Slf4j
@Service
public class TransHelper {
@Autowired
ContentParseHelper contentParseHelper;
@Autowired
RemoteArticleRepository remoteArticleRepository;
@Autowired
RemoteArticleInfoRepository remoteArticleInfoRepository;
@Value("${oss.prefix}")
String prefix;
public Boolean infoExists(RemoteArticle remoteArticle) {
return remoteArticleInfoRepository.exists(remoteArticle.getId());
}
public Article toArticle(RemoteArticle remoteArticle) {
RemoteArticleInfo remoteArticleInfo = remoteArticleInfoRepository.findOne(remoteArticle.getId());
return new Article(
newId(),
new Date(),
new Date(),
remoteArticleInfo.getChId(),
remoteArticle.getTitle(),
remoteArticleInfo.getPubTime(),
remoteArticleInfo.getOrderTime(),
remoteArticleInfo.getExamineTime(),
remoteArticle.getAuthor(),
remoteArticle.getSource(),
remoteArticle.getAds(),
remoteArticle.getKeyWord(),
getTypeString(remoteArticleInfo.getType()),
contentParseHelper.parseTitlePicFromContent(remoteArticle.getContent()),
remoteArticle.getContent(),
remoteArticleInfo.getClick().toString(),
remoteArticleInfo.getOnTop(),
remoteArticleInfo.getCatchMode(),
remoteArticleInfo.getClick().toString()
);
}
public Article toArticle(RemoteArticleInfo remoteArticleInfo) {
RemoteArticle remoteArticle = remoteArticleRepository.findOne(remoteArticleInfo.getId());
return new Article(
newId(),
new Date(),
new Date(),
remoteArticleInfo.getChId(),
remoteArticle.getTitle(),
remoteArticleInfo.getPubTime(),
remoteArticleInfo.getOrderTime(),
remoteArticleInfo.getExamineTime(),
remoteArticle.getAuthor(),
remoteArticle.getSource(),
remoteArticle.getAds(),
remoteArticle.getKeyWord(),
remoteArticleInfo.getType().toString(),
contentParseHelper.parseTitlePicFromContent(remoteArticle.getContent()),
remoteArticle.getContent(),
remoteArticleInfo.getClick().toString(),
remoteArticleInfo.getOnTop(),
remoteArticleInfo.getCatchMode(),
remoteArticleInfo.getClick().toString()
);
}
public Channel toChannel(RemoteChannel remoteChannel) {
return new Channel(
newId(),
new Date(),
new Date(),
"",
remoteChannel.getName(),
remoteChannel.getIntroduce(),
remoteChannel.getOrder()
);
}
public Stream<Annex> toAnnexStream(Article article) {
List<String> paths = contentParseHelper.getPaths(article.getContent());
List<Annex> result = paths.stream()
.map(path -> new Annex(
newId(),
new Date(),
new Date(),
article.getUuid(),
article.getTitle(),
path,
article.getAds()
))
.collect(Collectors.toList());
return result.stream();
}
public Stream<String> toPathStream(Article article) {
List<String> paths = contentParseHelper.getPaths(article.getContent());
return paths.stream();
}
public Article replaceContent(Article article) {
String newContent = contentParseHelper.replacePaths(article.getContent());
newContent = contentParseHelper.replaceRepeatedPaths(newContent);
return article.replaceContent(newContent);
}
public Annex replacePath(Annex annex) {
String newPath = contentParseHelper.replacePath(annex.getPath());
return annex.replacePath(newPath);
}
public String getFileName(String path) {
int index = path.lastIndexOf("/");
return path.substring(index + 1);
}
private String getTypeString(Integer type) {
if (Objects.equals(type, 0)) {
return "文章";
} else if (Objects.equals(type, 1)) {
return "图文";
} else {
return "";
}
}
private String newId(){
return UUID.randomUUID().toString();
}
}
package com.example.sqlserver.collector.task;
import com.example.sqlserver.collector.service.Updater;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* <p>Description : sqlserver-collector
* <p>Date : 2019/8/2 9:21
* <p>@author : C
*/
@Setter
@Component
public class Tasks {
private final
Updater updater;
@Autowired
public Tasks(Updater updater) {
this.updater = updater;
}
private Boolean isRunning = true;
/**
* 更新全部
*/
@Scheduled(initialDelay = 0, fixedRate = 60000 * 30)
public void updateAll() {
if (isRunning){
updater.updateAll();
}
}
/**
* 将需要更新的文章放入待更新缓存
*/
// @Scheduled(initialDelay = 0, fixedRate = 60000 * 1)
public void getRemoteArticlesForSave() {
if (isRunning){
updater.getRemoteArticlesForSave();
}
}
/**
* 将需要更新的栏目放入待更新缓存
*/
// @Scheduled(initialDelay = 0, fixedRate = 60000 * 1)
public void getRemoteTopicsForSave() {
if (isRunning){
updater.getRemoteChannelsForSave();
}
}
/**
* 更新保存文章
* 并将其内容中包含的附件放入待更新缓存
* 具备替换路径逻辑
* 一次从缓存中取100条来更新
*/
// @Scheduled(initialDelay = 10000, fixedRate = 60000*1)
public void updateArticleAndAttachment() {
if (isRunning) {
updater.updateArticlesAndAnnexes(1000);
}
}
/**
* 更新保存栏目
* 一次从缓存中取100条来更新
*/
// @Scheduled(initialDelay = 30000, fixedRate = 60000*1)
public void updateTopic() {
if (isRunning) {
updater.updateChannels(1000);
}
}
/**
* 更新保存附件
* 具备替换路径逻辑
* 一次从缓存中取100条来更新
*/
// @Scheduled(initialDelay = 10000, fixedRate = 60000*10)
public void uploadFile() {
if (isRunning){
updater.uploadFile(1000);
}
}
}
package com.example.sqlserver.collector.utils;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.*;
import org.springframework.stereotype.Component;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* oss 文件存储系统工具类
*
* @author mcj
*/
@Component
public class OssUtil {
private OSSClient ossClient;
{
String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
String accessKeyId = "LTAIu1wBaQJ9NkM9";
String accessKeySecret = "xzxlmm43htGZkK71ufefolIgSNE7Xt";
String bucketName = "mcjtest1";
// 创建OSSClient实例。
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
}
/**
* 获取所有存储空间名称
*
* @return list<string>
*/
public List<String> getBucket() {
List<Bucket> buckets = ossClient.listBuckets();
return buckets.stream()
.map(Bucket::getName)
.collect(Collectors.toList());
}
/**
* 对文件大小做分析
*/
public void upload() {
}
/**
* 普通上传文件推荐不要大于5g
*
* @param bucketName 存储空间名称
* @param fileName 文件名称
* @param inputStream 流
* @return true or false 代表上传成功失败
*/
public boolean uploadFile(String bucketName, String fileName, InputStream inputStream) {
try {
ossClient.putObject(bucketName, fileName, inputStream);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 分片上传
*
* @param bucketName 存储空间名称
* @param fileName 文件名称
* @param inputStream 文件流
*/
public void multipartupload(String bucketName, String fileName, InputStream inputStream) {
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, fileName);
InitiateMultipartUploadResult result = ossClient.initiateMultipartUpload(request);
// 返回uploadId,它是分片上传事件的唯一标识,您可以根据这个ID来发起相关的操作,如取消分片上传、查询分片上传等。
String uploadId = result.getUploadId();
// partETags是PartETag的集合。PartETag由分片的ETag和分片号组成。
List<PartETag> partETags = new ArrayList<PartETag>();
// 计算文件有多少个分片。
final long partSize = 1 * 1024 * 1024L;
final File sampleFile = new File("<localFile>");
long fileLength = sampleFile.length();
int partCount = (int) (fileLength / partSize);
if (fileLength % partSize != 0) {
partCount++;
}
for (int i = 0; i < partCount; i++) {
long startPos = i * partSize;
long curPartSize = (i + 1 == partCount) ? (fileLength - startPos) : partSize;
// 跳过已经上传的分片。
try {
inputStream.skip(startPos);
} catch (IOException e) {
e.printStackTrace();
}
UploadPartRequest uploadPartRequest = new UploadPartRequest();
uploadPartRequest.setBucketName(bucketName);
uploadPartRequest.setKey(fileName);
uploadPartRequest.setUploadId(uploadId);
uploadPartRequest.setInputStream(inputStream);
// 设置分片大小。除了最后一个分片没有大小限制,其他的分片最小为100KB。
uploadPartRequest.setPartSize(curPartSize);
// 设置分片号。每一个上传的分片都有一个分片号,取值范围是1~10000,如果超出这个范围,OSS将返回InvalidArgument的错误码。
uploadPartRequest.setPartNumber(i + 1);
// 每个分片不需要按顺序上传,甚至可以在不同客户端上传,OSS会按照分片号排序组成完整的文件。
UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
// 每次上传分片之后,OSS的返回结果会包含一个PartETag。PartETag将被保存到partETags中。
partETags.add(uploadPartResult.getPartETag());
}
Collections.sort(partETags, Comparator.comparingInt(PartETag::getPartNumber));
// 在执行该操作时,需要提供所有有效的partETags。OSS收到提交的partETags后,会逐一验证每个分片的有效性。当所有的数据分片验证通过后,OSS将把这些分片组合成一个完整的文件。
CompleteMultipartUploadRequest completeMultipartUploadRequest =
new CompleteMultipartUploadRequest(bucketName, fileName, uploadId, partETags);
ossClient.completeMultipartUpload(completeMultipartUploadRequest);
}
/**
* 断点上传
*/
public void checkpointUpload(String bucketName, String fileName, InputStream inputStream) {
// 通过UploadFileRequest设置多个参数。
UploadFileRequest uploadFileRequest = new UploadFileRequest(bucketName, fileName);
// 通过UploadFileRequest设置单个参数。
// 设置存储空间名称。
uploadFileRequest.setBucketName(bucketName);
// 设置文件名称。
uploadFileRequest.setKey(fileName);
// 指定上传的本地文件。
File file = new File("files");
try {
file.mkdirs();
byte[] bytes = new byte[1024 * 1024];
int len = 0;
FileOutputStream fileOutputStream = new FileOutputStream(file + "/" + fileName);
while ((len = inputStream.read(bytes)) != -1) {
fileOutputStream.write(bytes, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException ignored) {
}
uploadFileRequest.setUploadFile("files/" + fileName);
// 指定上传并发线程数,默认为1。
uploadFileRequest.setTaskNum(5);
// 指定上传的分片大小,范围为100KB~5GB,默认为文件大小/10000。
// 开启断点续传,默认关闭。
uploadFileRequest.setEnableCheckpoint(true);
// 记录本地分片上传结果的文件。开启断点续传功能时需要设置此参数,上传过程中的进度信息会保存在该文件中,如果某一分片上传失败,再次上传时会根据文件中记录的点继续上传。上传完成后,该文件会被删除。默认与待上传的本地文件同目录,为uploadFile.ucp。
// 设置上传成功回调,参数为Callback类型。
// 断点续传上传。
try {
ossClient.uploadFile(uploadFileRequest);
File file1 = new File("files/" + fileName);
System.out.println(file1.getName());
file1.delete();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
public void initClient() {
}
public void shotdownClient() {
}
}
#MySQL连接配置
spring.datasource.local.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.local.url=jdbc:mysql://localhost:3306/dzkjw?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true
spring.datasource.local.username=root
spring.datasource.local.password=root
#spring.jpa.hibernate.ddl-auto=update
#SQLserver连接配置
spring.datasource.remote.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.remote.url=jdbc:sqlserver://localhost:1433;DatabaseName=dzkjw;
spring.datasource.remote.username=sa
spring.datasource.remote.password=123456
#数据表命名选择不自动将"."替换为"_"的策略
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#oss.prefix = https://wskxoss.oss-cn-hangzhou-zjzwy01-d01-a.cloud.zj.gov.cn/taiyuan/dzkjw
oss.prefix = https://wskxoss.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn
oss.bucket = wskxoss
package com.example.sqlserver.collector;
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 SqlserverTestApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论