42 changed files with 3661 additions and 0 deletions
@ -0,0 +1,31 @@
|
||||
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/ |
@ -0,0 +1,118 @@
|
||||
/* |
||||
* Copyright 2007-present the original author or authors. |
||||
* |
||||
* Licensed 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.net.*; |
||||
import java.io.*; |
||||
import java.nio.channels.*; |
||||
import java.util.Properties; |
||||
|
||||
public class MavenWrapperDownloader { |
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6"; |
||||
/** |
||||
* 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/" |
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".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 directory '" + 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 { |
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { |
||||
String username = System.getenv("MVNW_USERNAME"); |
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); |
||||
Authenticator.setDefault(new Authenticator() { |
||||
@Override |
||||
protected PasswordAuthentication getPasswordAuthentication() { |
||||
return new PasswordAuthentication(username, password); |
||||
} |
||||
}); |
||||
} |
||||
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(); |
||||
} |
||||
|
||||
} |
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip |
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar |
Binary file not shown.
@ -0,0 +1,310 @@
|
||||
#!/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. |
||||
# ---------------------------------------------------------------------------- |
||||
|
||||
# ---------------------------------------------------------------------------- |
||||
# Maven 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)`" |
||||
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 |
||||
if [ -n "$MVNW_REPOURL" ]; then |
||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||
else |
||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||
fi |
||||
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 $cygwin; then |
||||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` |
||||
fi |
||||
|
||||
if command -v wget > /dev/null; then |
||||
if [ "$MVNW_VERBOSE" = true ]; then |
||||
echo "Found wget ... using wget" |
||||
fi |
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
||||
wget "$jarUrl" -O "$wrapperJarPath" |
||||
else |
||||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" |
||||
fi |
||||
elif command -v curl > /dev/null; then |
||||
if [ "$MVNW_VERBOSE" = true ]; then |
||||
echo "Found curl ... using curl" |
||||
fi |
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
||||
curl -o "$wrapperJarPath" "$jarUrl" -f |
||||
else |
||||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f |
||||
fi |
||||
|
||||
else |
||||
if [ "$MVNW_VERBOSE" = true ]; then |
||||
echo "Falling back to using Java to download" |
||||
fi |
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" |
||||
# For Cygwin, switch paths to Windows format before running javac |
||||
if $cygwin; then |
||||
javaClass=`cygpath --path --windows "$javaClass"` |
||||
fi |
||||
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 |
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will |
||||
# work with both Windows and non-Windows executions. |
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" |
||||
export MAVEN_CMD_LINE_ARGS |
||||
|
||||
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 "$@" |
@ -0,0 +1,182 @@
|
||||
@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 Maven 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 keystroke 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 by 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.5.6/maven-wrapper-0.5.6.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% ( |
||||
if "%MVNW_VERBOSE%" == "true" ( |
||||
echo Found %WRAPPER_JAR% |
||||
) |
||||
) else ( |
||||
if not "%MVNW_REPOURL%" == "" ( |
||||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||
) |
||||
if "%MVNW_VERBOSE%" == "true" ( |
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ... |
||||
echo Downloading from: %DOWNLOAD_URL% |
||||
) |
||||
|
||||
powershell -Command "&{"^ |
||||
"$webclient = new-object System.Net.WebClient;"^ |
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ |
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ |
||||
"}"^ |
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ |
||||
"}" |
||||
if "%MVNW_VERBOSE%" == "true" ( |
||||
echo Finished downloading %WRAPPER_JAR% |
||||
) |
||||
) |
||||
@REM End of extension |
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will |
||||
@REM work with both Windows and non-Windows executions. |
||||
set MAVEN_CMD_LINE_ARGS=%* |
||||
|
||||
%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% |
@ -0,0 +1,146 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>com.example</groupId> |
||||
<artifactId>ftpDemo</artifactId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
<name>ftpDemo</name> |
||||
<description>ftpDemo</description> |
||||
|
||||
<properties> |
||||
<java.version>1.8</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
<spring-boot.version>2.3.7.RELEASE</spring-boot.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-test</artifactId> |
||||
<scope>test</scope> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.junit.vintage</groupId> |
||||
<artifactId>junit-vintage-engine</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<!-- xxl-job-core --> |
||||
<dependency> |
||||
<groupId>com.xuxueli</groupId> |
||||
<artifactId>xxl-job-core</artifactId> |
||||
<version>2.3.1</version> |
||||
</dependency> |
||||
|
||||
<!-- org.apache.common.io提供了对FTP的开发 --> |
||||
<dependency> |
||||
<groupId>com.jcraft</groupId> |
||||
<artifactId>jsch</artifactId> |
||||
<version>0.1.54</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>commons-codec</groupId> |
||||
<artifactId>commons-codec</artifactId> |
||||
<version>1.10</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>1.2.35</version> |
||||
</dependency> |
||||
<!--lombook--> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<!--mvc--> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
<!--hutool--> |
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-all</artifactId> |
||||
<version>5.8.10</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>3.5.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-jdbc</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>mysql</groupId> |
||||
<artifactId>mysql-connector-java</artifactId> |
||||
</dependency> |
||||
<!--log4j--> |
||||
<dependency> |
||||
<groupId>log4j</groupId> |
||||
<artifactId>log4j</artifactId> |
||||
<version>1.2.17</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>io.swagger</groupId> |
||||
<artifactId>swagger-annotations</artifactId> |
||||
<version>1.6.6</version> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
|
||||
<dependencyManagement> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-dependencies</artifactId> |
||||
<version>${spring-boot.version}</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</dependencyManagement> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.8.1</version> |
||||
<configuration> |
||||
<source>1.8</source> |
||||
<target>1.8</target> |
||||
<encoding>UTF-8</encoding> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<version>2.3.7.RELEASE</version> |
||||
<configuration> |
||||
<mainClass>com.example.ftpdemo.FtpDemoApplication</mainClass> |
||||
</configuration> |
||||
<executions> |
||||
<execution> |
||||
<id>repackage</id> |
||||
<goals> |
||||
<goal>repackage</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,13 @@
|
||||
package com.example.ftpdemo; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
@SpringBootApplication |
||||
public class FtpDemoApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(FtpDemoApplication.class, args); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.example.ftpdemo.cache; |
||||
|
||||
|
||||
import com.example.ftpdemo.entity.SysDict; |
||||
import com.example.ftpdemo.service.SysDictService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
import javax.annotation.PreDestroy; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Component |
||||
public class CodeCache { |
||||
public static Map<String, String> codeMap = new HashMap<String, String>(); |
||||
|
||||
@Autowired |
||||
private SysDictService codeService; |
||||
|
||||
@PostConstruct |
||||
public void init(){ |
||||
System.out.println("系统启动中。。。加载codeMap"); |
||||
List<SysDict> codeList = codeService.selectAll(); |
||||
for (SysDict code : codeList) { |
||||
codeMap.put(code.getDictCode(), code.getDictValue()); |
||||
} |
||||
} |
||||
|
||||
@PreDestroy |
||||
public void destroy(){ |
||||
System.out.println("系统运行结束"); |
||||
} |
||||
} |
@ -0,0 +1,78 @@
|
||||
package com.example.ftpdemo.config; |
||||
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* xxl-job config |
||||
* |
||||
* @author xuxueli 2017-04-28 |
||||
*/ |
||||
@Configuration |
||||
public class XxlJobConfig { |
||||
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); |
||||
|
||||
@Value("${xxl.job.admin.addresses}") |
||||
private String adminAddresses; |
||||
|
||||
@Value("${xxl.job.accessToken}") |
||||
private String accessToken; |
||||
|
||||
@Value("${xxl.job.executor.appname}") |
||||
private String appname; |
||||
|
||||
@Value("${xxl.job.executor.address}") |
||||
private String address; |
||||
|
||||
@Value("${xxl.job.executor.ip}") |
||||
private String ip; |
||||
|
||||
@Value("${xxl.job.executor.port}") |
||||
private int port; |
||||
|
||||
@Value("${xxl.job.executor.logpath}") |
||||
private String logPath; |
||||
|
||||
@Value("${xxl.job.executor.logretentiondays}") |
||||
private int logRetentionDays; |
||||
|
||||
|
||||
@Bean |
||||
public XxlJobSpringExecutor xxlJobExecutor() { |
||||
logger.info(">>>>>>>>>>> xxl-job config init."); |
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); |
||||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses); |
||||
xxlJobSpringExecutor.setAppname(appname); |
||||
xxlJobSpringExecutor.setAddress(address); |
||||
xxlJobSpringExecutor.setIp(ip); |
||||
xxlJobSpringExecutor.setPort(port); |
||||
xxlJobSpringExecutor.setAccessToken(accessToken); |
||||
xxlJobSpringExecutor.setLogPath(logPath); |
||||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); |
||||
|
||||
return xxlJobSpringExecutor; |
||||
} |
||||
|
||||
/** |
||||
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; |
||||
* |
||||
* 1、引入依赖: |
||||
* <dependency> |
||||
* <groupId>org.springframework.cloud</groupId> |
||||
* <artifactId>spring-cloud-commons</artifactId> |
||||
* <version>${version}</version> |
||||
* </dependency> |
||||
* |
||||
* 2、配置文件,或者容器启动变量 |
||||
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' |
||||
* |
||||
* 3、获取IP |
||||
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
||||
*/ |
||||
|
||||
|
||||
} |
@ -0,0 +1,385 @@
|
||||
package com.example.ftpdemo.controller; |
||||
|
||||
import com.jcraft.jsch.*; |
||||
import com.xxl.job.core.context.XxlJobHelper; |
||||
|
||||
import java.io.*; |
||||
import java.util.*; |
||||
|
||||
|
||||
public class SSHRemoteCall { |
||||
|
||||
private static final int DEFAULT_PORT = 30020;// 默认端口号
|
||||
// 私有的对象
|
||||
private static SSHRemoteCall sshRemoteCall; |
||||
|
||||
// 懒汉式,线程不安全,适合单线程
|
||||
// public static SSHRemoteCall getInstance() {
|
||||
// if (sshRemoteCall == null) {
|
||||
// sshRemoteCall = new SSHRemoteCall();
|
||||
// }
|
||||
// return sshRemoteCall;
|
||||
// }
|
||||
private static String ipAddress = "223.99.228.240";// ip地址
|
||||
private static String userName = "root";// 账号
|
||||
private static String password = "Qingniao@123!";// 密码
|
||||
private int port;// 端口号
|
||||
private Session session;// JSCH session
|
||||
private boolean logined = false;// 是否登陆
|
||||
|
||||
/** |
||||
* 私有的构造方法 |
||||
*/ |
||||
private SSHRemoteCall() { |
||||
} |
||||
|
||||
/** |
||||
* 构造方法,可以直接使用DEFAULT_PORT |
||||
* |
||||
* @param ipAddress |
||||
* @param userName |
||||
* @param password |
||||
*/ |
||||
public SSHRemoteCall(String ipAddress, String userName, String password) { |
||||
this(ipAddress, DEFAULT_PORT, userName, password); |
||||
} |
||||
|
||||
/** |
||||
* 构造方法,方便直接传入ipAddress,userName,password进行调用 |
||||
* |
||||
* @param ipAddress |
||||
* @param port |
||||
* @param userName |
||||
* @param password |
||||
*/ |
||||
public SSHRemoteCall(String ipAddress, int port, String userName, String password) { |
||||
super(); |
||||
this.ipAddress = ipAddress; |
||||
this.userName = userName; |
||||
this.password = password; |
||||
this.port = port; |
||||
} |
||||
|
||||
// 懒汉式,线程安全,适合多线程
|
||||
public static synchronized SSHRemoteCall getInstance() { |
||||
if (sshRemoteCall == null) { |
||||
sshRemoteCall = new SSHRemoteCall(); |
||||
} |
||||
return sshRemoteCall; |
||||
} |
||||
|
||||
/** |
||||
* 远程登陆 |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
public void sshRemoteCallLogin(String ipAddress, String userName, String password) throws Exception { |
||||
// 如果登陆就直接返回
|
||||
if (logined) { |
||||
return; |
||||
} |
||||
// 创建jSch对象
|
||||
JSch jSch = new JSch(); |
||||
try { |
||||
// 获取到jSch的session, 根据用户名、主机ip、端口号获取一个Session对象
|
||||
session = jSch.getSession(userName, ipAddress, 22102); //22102
|
||||
// 设置密码
|
||||
session.setPassword(password); |
||||
|
||||
// 方式一,通过Session建立连接
|
||||
// session.setConfig("StrictHostKeyChecking", "no");
|
||||
// session.connect();
|
||||
|
||||
// 方式二,通过Session建立连接
|
||||
// java.util.Properties;
|
||||
// Properties config = new Properties();
|
||||
// config.put("StrictHostKeyChecking", "no");
|
||||
// session.setConfig(config);// 为Session对象设置properties
|
||||
// session.setTimeout( );// 设置超时
|
||||
session.setConfig("StrictHostKeyChecking", "no"); |
||||
session.connect();//// 通过Session建立连接
|
||||
|
||||
// 设置登陆状态
|
||||
logined = true; |
||||
} catch (JSchException e) { |
||||
// 设置登陆状态为false
|
||||
logined = false; |
||||
throw new Exception( |
||||
"主机登录失败, IP = " + ipAddress + ", USERNAME = " + userName + ", Exception:" + e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 关闭连接 |
||||
*/ |
||||
public void closeSession() { |
||||
// 调用session的关闭连接的方法
|
||||
if (session != null) { |
||||
// 如果session不为空,调用session的关闭连接的方法
|
||||
session.disconnect(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 执行相关的命令 |
||||
* |
||||
* @param command |
||||
* @throws IOException |
||||
*/ |
||||
public String execCommand(String command) throws IOException { |
||||
InputStream in = null;// 输入流(读)
|
||||
Channel channel = null;// 定义channel变量
|
||||
try { |
||||
// 如果命令command不等于null
|
||||
if (command != null) { |
||||
// 打开channel
|
||||
//说明:exec用于执行命令;sftp用于文件处理
|
||||
channel = session.openChannel("exec"); |
||||
// 设置command
|
||||
((ChannelExec) channel).setCommand(command); |
||||
// channel进行连接
|
||||
channel.connect(); |
||||
// 获取到输入流
|
||||
in = channel.getInputStream(); |
||||
// 执行相关的命令
|
||||
String processDataStream = processDataStream(in); |
||||
// 打印相关的命令
|
||||
return processDataStream; |
||||
} |
||||
} catch (JSchException e) { |
||||
e.printStackTrace(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (in != null) { |
||||
in.close(); |
||||
} |
||||
if (channel != null) { |
||||
channel.disconnect(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 对将要执行的linux的命令进行遍历 |
||||
* |
||||
* @param in |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public String processDataStream(InputStream in) throws Exception { |
||||
StringBuffer sb = new StringBuffer(); |
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
||||
String result = ""; |
||||
try { |
||||
while ((result = br.readLine()) != null) { |
||||
sb.append(result); |
||||
// System.out.println(sb.toString());
|
||||
} |
||||
} catch (Exception e) { |
||||
throw new Exception("获取数据流失败: " + e); |
||||
} finally { |
||||
br.close(); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 上传文件 可参考:https://www.cnblogs.com/longyg/archive/ / / / .html
|
||||
* |
||||
* @param directory 上传文件的目录 |
||||
* @param uploadFile 将要上传的文件 |
||||
*/ |
||||
public void uploadFile(String directory, String uploadFile) { |
||||
try { |
||||
// 打开channelSftp
|
||||
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(6000); |
||||
// 创建一个文件名称问uploadFile的文件
|
||||
File file = new File(uploadFile); |
||||
// 将文件进行上传(sftp协议)
|
||||
// 将本地文件名为src的文件上传到目标服务器,目标文件名为dst,若dst为目录,则目标文件名将与src文件名相同.
|
||||
// 采用默认的传输模式:OVERWRITE
|
||||
channelSftp.put(new FileInputStream(file), directory, ChannelSftp.OVERWRITE); |
||||
// 切断远程连接
|
||||
channelSftp.exit(); |
||||
XxlJobHelper.log("上传文件:" + file.getName()); |
||||
} catch (JSchException e) { |
||||
e.printStackTrace(); |
||||
} catch (SftpException e) { |
||||
e.printStackTrace(); |
||||
} catch (FileNotFoundException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 下载文件 采用默认的传输模式:OVERWRITE |
||||
* |
||||
* @param src linux服务器文件地址 |
||||
* @param dst 本地存放地址 |
||||
* @throws JSchException |
||||
* @throws SftpException |
||||
*/ |
||||
public void fileDownload(String src, String dst) throws JSchException, SftpException { |
||||
// src 是linux服务器文件地址,dst 本地存放地址
|
||||
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(); |
||||
// 下载文件,多个重载方法
|
||||
channelSftp.get(src, dst); |
||||
// 切断远程连接,quit()等同于exit(),都是调用disconnect()
|
||||
channelSftp.quit(); |
||||
// channelSftp.disconnect();
|
||||
System.out.println("下载文件:" + src); |
||||
} |
||||
|
||||
/** |
||||
* 删除文件 |
||||
* |
||||
* @throws SftpException |
||||
* @throws JSchException |
||||
*/ |
||||
public void deleteFile(String directoryFile) throws SftpException, JSchException { |
||||
// 打开openChannel的sftp
|
||||
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(); |
||||
// 删除文件
|
||||
channelSftp.rm(directoryFile); |
||||
// 切断远程连接
|
||||
channelSftp.exit(); |
||||
System.out.println("删除文件:" + directoryFile); |
||||
} |
||||
|
||||
/** |
||||
* 如果此目录不存在将新建目录 |
||||
*/ |
||||
public void directory(String path) { |
||||
// 打开openChannel的sftp
|
||||
ChannelSftp channelSftp = null; |
||||
try { |
||||
channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(6000); |
||||
// 切换到主目录
|
||||
// channelSftp.cd("/");
|
||||
} catch (JSchException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
String[] folders = path.split("/"); |
||||
for (String folder : folders) { |
||||
if (folder.length() > 0) { |
||||
try { |
||||
channelSftp.cd(folder); |
||||
// XxlJobHelper.log("切换目录" + folder);
|
||||
} catch (SftpException e) { |
||||
try { |
||||
channelSftp.mkdir(folder); |
||||
XxlJobHelper.log("生成目录" + folder); |
||||
channelSftp.cd(folder); |
||||
} catch (SftpException ex) { |
||||
throw new RuntimeException(ex); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
channelSftp.disconnect(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 列出目录下的文件 |
||||
* |
||||
* @param directory 要列出的目录 |
||||
* @return |
||||
* @throws SftpException |
||||
* @throws JSchException |
||||
*/ |
||||
public Vector listFilesBack(String directory) throws JSchException, SftpException { |
||||
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(); |
||||
// 显示目录信息
|
||||
Vector ls = channelSftp.ls(directory); |
||||
|
||||
Iterator iterator = ls.iterator(); |
||||
|
||||
Map<String, File> fileMap = new HashMap<>(); |
||||
|
||||
try { |
||||
|
||||
while (iterator.hasNext()) { |
||||
ChannelSftp.LsEntry file = (ChannelSftp.LsEntry) iterator.next(); |
||||
//文件名称
|
||||
String fileName = file.getFilename(); |
||||
System.out.println(fileName); |
||||
//todo 这里可使用if或正则不下载一些文件
|
||||
InputStream inputStream = channelSftp.get(directory + fileName); |
||||
if (inputStream != null) { |
||||
File newFile = new File(fileName); |
||||
//将InputStream转File
|
||||
// FileUtils.copyToFile(inputStream, newFile);
|
||||
fileMap.put(fileName, newFile); |
||||
} |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
// 切断连接
|
||||
channelSftp.exit(); |
||||
} |
||||
|
||||
return ls; |
||||
} |
||||
|
||||
/** |
||||
* 列出目录下的文件 |
||||
* |
||||
* @param directory 要列出的目录 |
||||
* @return |
||||
* @throws SftpException |
||||
* @throws JSchException |
||||
*/ |
||||
public List<String> listFiles(String directory) throws JSchException, SftpException { |
||||
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); |
||||
// 远程连接
|
||||
channelSftp.connect(); |
||||
// 显示目录信息
|
||||
Vector ls = channelSftp.ls(directory); |
||||
|
||||
|
||||
Iterator iterator = ls.iterator(); |
||||
|
||||
try { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
while (iterator.hasNext()) { |
||||
ChannelSftp.LsEntry file = (ChannelSftp.LsEntry) iterator.next(); |
||||
//文件名称
|
||||
String fileName = file.getFilename(); |
||||
//移除上级目录和根目录:"." ".."
|
||||
if (".".equals(fileName) || "..".equals(fileName)) { |
||||
continue; |
||||
} |
||||
list.add(fileName); |
||||
} |
||||
return list; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
// 切断连接
|
||||
channelSftp.exit(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.example.ftpdemo.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/25 |
||||
*/ |
||||
@Data |
||||
public class Identification { |
||||
// 标识码企业前缀
|
||||
private String companyCode; |
||||
//标识解析节点经营主体名称
|
||||
private String companyName; |
||||
//标识解析系统级别
|
||||
private int level; |
||||
//接入省份
|
||||
private String accessProvince; |
||||
//接入地市
|
||||
private String accessCity; |
||||
//注册时间
|
||||
private String registerTime; |
||||
//经营主体行业门类
|
||||
private String categoryA; |
||||
//经营主体行业大类
|
||||
private String categoryB; |
||||
//公司性质
|
||||
private String companyType; |
||||
//节点服务行业
|
||||
private String serviceProfession; |
||||
|
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.example.ftpdemo.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
@Data |
||||
@TableName("nbms_ent_prefix") |
||||
public class NbmsEnprefix implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
|
||||
@ApiModelProperty(value = "主键ID") |
||||
private Long id; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
||||
@ApiModelProperty(value = "") |
||||
private Date createDate; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
||||
@ApiModelProperty(value = "") |
||||
private Date updateDate; |
||||
|
||||
@ApiModelProperty(value = "企业通用id") |
||||
private String entGeneralId; |
||||
|
||||
@ApiModelProperty(value = "企业名称") |
||||
private String entName; |
||||
|
||||
@ApiModelProperty(value = "企业用户ID") |
||||
private Long userId; |
||||
|
||||
@ApiModelProperty(value = "标识前缀") |
||||
private String entPrefix; |
||||
|
||||
@ApiModelProperty(value = "状态是否有效 1启用2停用") |
||||
private Integer state; |
||||
|
||||
@ApiModelProperty(value = "托管状态 1未托管2托管申请中3托管被驳回4已托管") |
||||
private Integer proxyState; |
||||
|
||||
@ApiModelProperty(value = "前缀历史状态是否有效 0停用1启用") |
||||
private Integer historyState; |
||||
|
||||
@ApiModelProperty(value = "路由 0:否,1:是") |
||||
private Integer isDeleted; |
||||
|
||||
@ApiModelProperty(value = "路由xml创建状态") |
||||
private Integer xmlCreated; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
||||
@ApiModelProperty(value = "路由最新上传时间") |
||||
private Date xmlUpdateTime; |
||||
|
||||
@ApiModelProperty(value = "路由xml删除状态") |
||||
private Integer xmlDeleted; |
||||
|
||||
@ApiModelProperty(value = "路由同步状态1同步,0待同步,2同步中") |
||||
private Integer xmlSync; |
||||
|
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.example.ftpdemo.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@TableName("nbms_ent") |
||||
@Data |
||||
public class NbmsEnt { |
||||
private long id; |
||||
private Date createDate; |
||||
private Date updateDate; |
||||
private String contactEmail; |
||||
private String orgAddr; |
||||
private String orgAddrCity; |
||||
private String orgAddrCounty; |
||||
private String orgCrtCode; |
||||
private int orgCrtType; |
||||
private String orgDesc; |
||||
private String entGeneralId; |
||||
private String industryCategory; |
||||
private String orgName; |
||||
private String orgAddrProvince; |
||||
private String industrySpecific; |
||||
private int orgNature; |
||||
private String website; |
||||
private String legalCrtNo; |
||||
private int legalCrtType; |
||||
private String legalName; |
||||
private String contactPhone; |
||||
private Integer operateType; |
||||
private Long userId; |
||||
private String userName; |
||||
private String contactName; |
||||
private Integer sync; |
||||
private Integer contactCrtType; |
||||
private String contactCrtNo; |
||||
private String regAuthority; |
||||
private Long regCapital; |
||||
private Date establishDate; |
||||
private Date periodValidity; |
||||
private String legalEmail; |
||||
private String legalPhone; |
||||
private String legalFax; |
||||
private Integer servSysBuildType; |
||||
private String servSysBuildName; |
||||
private Integer servSysOperType; |
||||
private String servSysOperName; |
||||
private String dataHostingOrg; |
||||
private String servHostingOrg; |
||||
private Integer regRealNaImpType; |
||||
private String regRealNaImpName; |
||||
private String idRegNaImp; |
||||
private String extWebName; |
||||
private String extDomain; |
||||
private String extIpAddr; |
||||
private Long orgCrtImgRid; |
||||
private Long contactCrtFrontImgRid; |
||||
private Long contactCrtBackImgRid; |
||||
private Long legalCrtFrontImgRid; |
||||
private Long legalCrtBackImgRid; |
||||
private Long servSysBuildContractFileRid; |
||||
private Long servSysOperContractFileRid; |
||||
private Long dataHostingContractFileRid; |
||||
private Long servHostingContractFileRid; |
||||
private Integer isDeleted; |
||||
private Integer xmlCreated; |
||||
private Date xmlUpdateTime; |
||||
private Integer xmlDeleted; |
||||
private Integer xmlSync; |
||||
} |
@ -0,0 +1,222 @@
|
||||
package com.example.ftpdemo.entity; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
@TableName("nbms_ent_apply") |
||||
@Data |
||||
public class NbmsEntApply implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
|
||||
@ApiModelProperty(value = "主键ID") |
||||
private Long id; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
@ApiModelProperty(value = "") |
||||
private Date createDate; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
@ApiModelProperty(value = "") |
||||
private Date updateDate; |
||||
|
||||
@ApiModelProperty(value = "1注册2部分修改3全量修改4分配前缀") |
||||
private Integer applyType; |
||||
|
||||
@ApiModelProperty(value = "联系人邮箱,正则表达式:") |
||||
private String contactEmail; |
||||
|
||||
@ApiModelProperty(value = "单位地址,详细地址") |
||||
private String orgAddr; |
||||
|
||||
@ApiModelProperty(value = "单位地址,市,取值遵从全国省市区行政编码,如北京市则展示为直辖市,取值110100") |
||||
private String orgAddrCity; |
||||
|
||||
@ApiModelProperty(value = "单位地址,县,取值遵从全国省市区行政编码,如北京的东城区110101") |
||||
private String orgAddrCounty; |
||||
|
||||
@ApiModelProperty(value = "单位证件号") |
||||
private String orgCrtCode; |
||||
|
||||
@ApiModelProperty(value = "单位证件类型,统一社会信用代码、其他,对应取值1-2") |
||||
private Integer orgCrtType; |
||||
|
||||
@ApiModelProperty(value = "单位简介,200字左右企业简介,包括公司名称、成立时间、所在省市、主营业务、主要用户群体、行业地位等信息。") |
||||
private String orgDesc; |
||||
|
||||
@ApiModelProperty(value = "企业通用id,注册时为空") |
||||
private String entGeneralId; |
||||
|
||||
@ApiModelProperty(value = "服务行业,行业门类,参考《GB/T 4754—2017国民经济行业分类》,如门类“农、林、牧、渔业”对应“A”") |
||||
private String industryCategory; |
||||
|
||||
@ApiModelProperty(value = "单位名称") |
||||
private String orgName; |
||||
|
||||
@ApiModelProperty(value = "单位地址,省,取值遵从全国省市区行政编码,如北京110000") |
||||
private String orgAddrProvince; |
||||
|
||||
@ApiModelProperty(value = "服务行业,行业大类,参考《GB/T 4754—2017国民经济行业分类》,如大类“农业”对应“01”。和门类有级联关系") |
||||
private String industrySpecific; |
||||
|
||||
@ApiModelProperty(value = "单位性质,国有控股、民营控股、外商控股、事业单位、民营非盈利,对应取值1-5") |
||||
private Integer orgNature; |
||||
|
||||
@ApiModelProperty(value = "官方网站") |
||||
private String website; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private String industry; |
||||
|
||||
@ApiModelProperty(value = "0未提交1已提交") |
||||
private Integer isSubmit; |
||||
|
||||
@ApiModelProperty(value = "法定代表人证件号") |
||||
private String legalCrtNo; |
||||
|
||||
@ApiModelProperty(value = "法定代表人证件类型,中国居民身份证、护照、其他,对应取值1-3") |
||||
private Integer legalCrtType; |
||||
|
||||
@ApiModelProperty(value = "法定代表人姓名") |
||||
private String legalName; |
||||
|
||||
@ApiModelProperty(value = "联系人手机号,正则表达式") |
||||
private String contactPhone; |
||||
|
||||
@ApiModelProperty(value = "企业前缀") |
||||
private String entPrefix; |
||||
|
||||
@ApiModelProperty(value = "节点用户给出的审核状态:1待审核2审核通过3被驳回") |
||||
private Integer firstAuditStatus; |
||||
|
||||
@ApiModelProperty(value = "节点用户给出的审核结果描述") |
||||
private String firstAuditMsg; |
||||
|
||||
@ApiModelProperty(value = "实名核验结果") |
||||
private Integer thirdServiceStatus; |
||||
|
||||
@ApiModelProperty(value = "实名核验结果说明") |
||||
private String thirdServiceMsg; |
||||
|
||||
@ApiModelProperty(value = "企业用户名称不能为空") |
||||
private String userName; |
||||
|
||||
@ApiModelProperty(value = "顶级bms给出的审核状态:1待审核2审核通过3被驳回") |
||||
private Integer finalAuditStatus; |
||||
|
||||
@ApiModelProperty(value = "顶级bms企业审核员对企业信息的审核结果描述") |
||||
private String finalAuditMsg; |
||||
|
||||
@ApiModelProperty(value = "svTRId: 服务端id自动生成") |
||||
@TableField("svTRId") |
||||
private String svTRId; |
||||
|
||||
@ApiModelProperty(value = "clTRId: 客户端Id") |
||||
@TableField("clTRId") |
||||
private String clTRId; |
||||
|
||||
@ApiModelProperty(value = "联系人姓名") |
||||
private String contactName; |
||||
|
||||
@ApiModelProperty(value = "企业用户id") |
||||
private Long userId; |
||||
|
||||
@ApiModelProperty(value = "申请前缀执行到的第几步") |
||||
private Integer applyStep; |
||||
|
||||
@ApiModelProperty(value = "联系人证件类型,中国居民身份证、护照、其他,对应取值1-3") |
||||
private Integer contactCrtType; |
||||
|
||||
@ApiModelProperty(value = "联系人证件号") |
||||
private String contactCrtNo; |
||||
|
||||
@ApiModelProperty(value = "注册机关") |
||||
private String regAuthority; |
||||
|
||||
@ApiModelProperty(value = "注册资本,单位元") |
||||
private Long regCapital; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
@ApiModelProperty(value = "成立日期,时间格式:yyyy-MM-dd ") |
||||
private Date establishDate; |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
@ApiModelProperty(value = "有效期") |
||||
private Date periodValidity; |
||||
|
||||
@ApiModelProperty(value = "法人代表人邮箱,正则表达式:") |
||||
private String legalEmail; |
||||
|
||||
@ApiModelProperty(value = "法人代表人手机号,正则表达式") |
||||
private String legalPhone; |
||||
|
||||
@ApiModelProperty(value = "法人代表人传真") |
||||
private String legalFax; |
||||
|
||||
@ApiModelProperty(value = "服务系统建设,建设类型,□自营 □委托 描述对应的编码取值1-2") |
||||
private Integer servSysBuildType; |
||||
|
||||
@ApiModelProperty(value = "委托机构名称,委托机构名称,建设类型选“委托”,该字段必填") |
||||
private String servSysBuildName; |
||||
|
||||
@ApiModelProperty(value = "服务系统运营,运营类型,□自营 □委托 描述对应的编码取值1-2") |
||||
private Integer servSysOperType; |
||||
|
||||
@ApiModelProperty(value = "服务系统运营,委托机构名称,建设类型选“委托”,该字段必填") |
||||
private String servSysOperName; |
||||
|
||||
@ApiModelProperty(value = "数据托管单位,例:国家顶级节点(北京)") |
||||
private String dataHostingOrg; |
||||
|
||||
@ApiModelProperty(value = "服务托管单位,例:南京ZB节点") |
||||
private String servHostingOrg; |
||||
|
||||
@ApiModelProperty(value = "注册实名核验实施,实施类型□自营 □委托 描述对应的编码取值1-2") |
||||
private Integer regRealNaImpType; |
||||
|
||||
@ApiModelProperty(value = "注册实名核验实施,委托机构名称,建设类型选“委托”,该字段必填") |
||||
private String regRealNaImpName; |
||||
|
||||
@ApiModelProperty(value = "标识注册名称合规实施") |
||||
private String idRegNaImp; |
||||
|
||||
@ApiModelProperty(value = "对外提供标识服务的网站名称、域名、IP地址,网站名称") |
||||
private String extWebName; |
||||
|
||||
@ApiModelProperty(value = "对外提供标识服务的网站名称、域名、IP地址,域名") |
||||
private String extDomain; |
||||
|
||||
@ApiModelProperty(value = "对外提供标识服务的网站名称、域名、IP地址,IP地址,支持IPv4和IPv6,多个IP间以;分割") |
||||
private String extIpAddr; |
||||
|
||||
@ApiModelProperty(value = "营业执照") |
||||
private Long orgCrtImgRid; |
||||
|
||||
@ApiModelProperty(value = "联系人证件照正面") |
||||
private Long contactCrtFrontImgRid; |
||||
|
||||
@ApiModelProperty(value = "联系人证件照反面") |
||||
private Long contactCrtBackImgRid; |
||||
|
||||
@ApiModelProperty(value = "法人证件照正面") |
||||
private Long legalCrtFrontImgRid; |
||||
|
||||
@ApiModelProperty(value = "法人证件照反面") |
||||
private Long legalCrtBackImgRid; |
||||
|
||||
@ApiModelProperty(value = "服务系统建设合同") |
||||
private Long servSysBuildContractFileRid; |
||||
|
||||
@ApiModelProperty(value = "服务系统运营合同") |
||||
private Long servSysOperContractFileRid; |
||||
|
||||
@ApiModelProperty(value = "数据托管合同") |
||||
private Long dataHostingContractFileRid; |
||||
|
||||
@ApiModelProperty(value = "服务托管合同") |
||||
private Long servHostingContractFileRid; |
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.example.ftpdemo.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Data |
||||
@TableName("sys_dict") |
||||
public class SysDict { |
||||
private Long id; |
||||
private String dictKey; |
||||
private String dictCode; |
||||
private String dictValue; |
||||
private Long parentId; |
||||
private Date createDate; |
||||
private Date updateDate; |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.example.ftpdemo.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import com.example.ftpdemo.entity.NbmsEnprefix; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Mapper |
||||
public interface NbmsEnprefixMapper extends BaseMapper<NbmsEnprefix> { |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.example.ftpdemo.mapper; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import com.example.ftpdemo.entity.NbmsEntApply; |
||||
|
||||
/** |
||||
* NbmsEnapplyMapper |
||||
* @author fuce_自动生成 |
||||
* @email ${email} |
||||
* @date 2022-11-28 17:12:08 |
||||
*/ |
||||
@Mapper |
||||
public interface NbmsEntApplyMapper extends BaseMapper<NbmsEntApply> { |
||||
|
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.example.ftpdemo.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import com.example.ftpdemo.entity.NbmsEnt; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Mapper |
||||
public interface NbmsEntMapper extends BaseMapper<NbmsEnt> { |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.example.ftpdemo.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import com.example.ftpdemo.entity.SysDict; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Mapper |
||||
public interface SysDictMapper extends BaseMapper<SysDict> { |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
|
||||
import java.io.File; |
||||
|
||||
/** |
||||
* 四、 标识解析节点使用IP段上报 |
||||
* |
||||
* @author laifeng |
||||
* @since 2022/11/27 |
||||
*/ |
||||
@AllArgsConstructor |
||||
public class IdentificationIp { |
||||
|
||||
private final Method method; |
||||
public static void main(String[] args) throws Exception { |
||||
|
||||
// String fileName = "d://aaa//test.txt";
|
||||
// // 要上传的目录
|
||||
// String upSrc = "/002/" + DateUtil.format(DateUtil.now(), "yyyyMMdd");
|
||||
// // 表名(文件名的一部分)
|
||||
// String tableName = "SDQN-basic_identification_ip-";
|
||||
// // 操作类型为新增
|
||||
// String operationName = "-add.bin";
|
||||
// method.upMethod(fileName, upSrc, tableName, operationName);
|
||||
|
||||
|
||||
} |
||||
|
||||
public static void deleteFile(String src) { |
||||
|
||||
System.out.println(src); |
||||
File file = new File(src); |
||||
boolean delete = file.delete(); |
||||
System.out.println(delete); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/27 |
||||
*/ |
||||
public interface Method { |
||||
void upMethod(String readFile, String upSrc, String tableName, String operationName) throws Exception; |
||||
|
||||
Boolean creatIdentificationUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException; |
||||
|
||||
Boolean creatForUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException; |
||||
|
||||
Boolean creatFiveUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException; |
||||
|
||||
void creatSixUpFileAndUp(String yesterday) throws Exception; |
||||
|
||||
void creatSevenUpFileAndUp(String yesterday) throws Exception; |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.example.ftpdemo.entity.NbmsEnprefix; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
public interface NbmsEnprefixService extends IService<NbmsEnprefix> { |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.example.ftpdemo.entity.NbmsEntApply; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
public interface NbmsEntApplyServcie extends IService<NbmsEntApply> { |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.example.ftpdemo.entity.NbmsEnt; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
public interface NbmsEntServcie extends IService<NbmsEnt> { |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.example.ftpdemo.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.example.ftpdemo.entity.SysDict; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
public interface SysDictService extends IService<SysDict> { |
||||
List<SysDict> selectAll(); |
||||
} |
@ -0,0 +1,480 @@
|
||||
package com.example.ftpdemo.service.impl; |
||||
|
||||
import cn.hutool.core.collection.CollUtil; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.example.ftpdemo.cache.CodeCache; |
||||
import com.example.ftpdemo.controller.SSHRemoteCall; |
||||
import com.example.ftpdemo.entity.NbmsEnprefix; |
||||
import com.example.ftpdemo.entity.NbmsEntApply; |
||||
import com.example.ftpdemo.service.Method; |
||||
import com.example.ftpdemo.service.NbmsEnprefixService; |
||||
import com.example.ftpdemo.service.NbmsEntApplyServcie; |
||||
import com.example.ftpdemo.util.Constant; |
||||
import com.example.ftpdemo.util.Encrypt; |
||||
import com.jcraft.jsch.*; |
||||
import com.xxl.job.core.context.XxlJobHelper; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.*; |
||||
import java.util.*; |
||||
import java.util.zip.GZIPInputStream; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/27 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MethodImpl implements Method { |
||||
private final NbmsEntApplyServcie nbmsEntApplyServcie; |
||||
|
||||
private final NbmsEnprefixService enprefixService; |
||||
|
||||
@Override |
||||
public void upMethod(String readFile, String upSrc, String tableName, String operationName) throws Exception { |
||||
|
||||
|
||||
File file = new File(readFile); |
||||
BufferedReader br = new BufferedReader(new InputStreamReader( |
||||
new FileInputStream(file))); |
||||
StringBuilder sb = new StringBuilder(); |
||||
String line = null; |
||||
while ((line = br.readLine()) != null) { |
||||
sb.append(line).append("\n"); |
||||
} |
||||
br.close(); |
||||
// 将字符串压缩成zip文件并获得字节数据
|
||||
byte[] bytes = Encrypt.zipToBytes(Constant.zipPath, sb.toString()); |
||||
// upload是压缩加密后的内容
|
||||
byte[] upload = Encrypt.encryptAlgorithm("1", bytes, "1234567890abcDEF", |
||||
"1234567890abcDEF"); |
||||
|
||||
// 生成文件名
|
||||
String dateStr = Long.toString(System.currentTimeMillis()); // 生成13位时间戳
|
||||
String fileName = tableName + dateStr + operationName; |
||||
String src = Constant.localPackage + fileName; |
||||
// 写入文件
|
||||
FileOutputStream stream = new FileOutputStream(src); |
||||
stream.write(upload); |
||||
XxlJobHelper.log("写入成功:" + fileName); |
||||
// 关闭输出流
|
||||
stream.close(); |
||||
|
||||
// 远程连接服务器
|
||||
SSHRemoteCall.getInstance().sshRemoteCallLogin(Constant.ipAddress, Constant.userName, Constant.password); |
||||
|
||||
// 确保目录一定存在
|
||||
SSHRemoteCall.getInstance().directory(upSrc); |
||||
// 上传文件到指定目录
|
||||
SSHRemoteCall.getInstance().uploadFile("/data1/qingniao/" + upSrc + "/" + fileName, src); |
||||
} |
||||
|
||||
/** |
||||
* 生成三、 标识解析企业主体信息上报文件 |
||||
* |
||||
* @param type 0 代表注册 1 代表修改 |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Boolean creatIdentificationUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException { |
||||
String companyCode; //标识码企业前缀
|
||||
String companyName; // 标识解析节点经营主体名称
|
||||
String level; // 标识解析系统级别
|
||||
String accessProvince; // 接入省份
|
||||
String accessCity; // 接入地市
|
||||
String registerTime; // 注册时间
|
||||
String categoryA; // 经营主体行业门类
|
||||
String categoryB; // 经营主体行业大类
|
||||
String companyType; // 公司性质
|
||||
String serviceProfession; //节点服务行业
|
||||
|
||||
List<NbmsEntApply> list = null; |
||||
// 新增操作
|
||||
if (type == 0) { |
||||
list = nbmsEntApplyServcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyType, 1) |
||||
.eq(NbmsEntApply::getApplyStep, 4) |
||||
.ge(NbmsEntApply::getUpdateDate, yyyyMMdd) |
||||
.le(NbmsEntApply::getUpdateDate, yyyyMMddToday) |
||||
.list(); |
||||
} |
||||
// 修改操作
|
||||
if (type == 1) { |
||||
list = nbmsEntApplyServcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyType, 2) |
||||
.eq(NbmsEntApply::getApplyType, 3) |
||||
.eq(NbmsEntApply::getApplyStep, 4) |
||||
.ge(NbmsEntApply::getUpdateDate, yyyyMMdd) |
||||
.le(NbmsEntApply::getUpdateDate, yyyyMMddToday) |
||||
.list(); |
||||
} |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
if (CollUtil.isNotEmpty(list)) { |
||||
for (NbmsEntApply nbmsEnapply : list) { |
||||
companyCode = nbmsEnapply.getEntPrefix(); |
||||
companyName = nbmsEnapply.getOrgName(); |
||||
level = "4"; |
||||
accessProvince = nbmsEnapply.getOrgAddrProvince(); |
||||
accessProvince = CodeCache.codeMap.get(accessProvince); |
||||
|
||||
accessCity = nbmsEnapply.getOrgAddrCity(); |
||||
accessCity = CodeCache.codeMap.get(accessCity); |
||||
|
||||
registerTime = DateUtil.format(nbmsEnapply.getUpdateDate(), "yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
categoryA = nbmsEnapply.getIndustrySpecific(); |
||||
categoryA = CodeCache.codeMap.get(categoryA); |
||||
|
||||
categoryB = nbmsEnapply.getIndustryCategory(); |
||||
categoryB = CodeCache.codeMap.get(categoryB); |
||||
|
||||
companyType = judge(nbmsEnapply.getOrgNature()); |
||||
serviceProfession = categoryB; |
||||
|
||||
String template = companyCode + "|" + companyName + "|" + level + "|" + accessProvince + "|" + accessCity + "|" + registerTime + "|" + categoryA + "|" + categoryB + "|" + companyType + "|" + serviceProfession + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 四、 标识解析企业主体信息上报 |
||||
* |
||||
* @param type 0 代表注册 1 代表修改 |
||||
*/ |
||||
@Override |
||||
public Boolean creatForUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException { |
||||
String companyName; // 标识解析节点经营主体名称
|
||||
String startIP = "223.99.228.240"; |
||||
String endIP = "223.99.228.240"; |
||||
String position = "中国山东省济南市自由贸易试验区济南片区颖秀路2299号"; |
||||
List<NbmsEnprefix> list = null; |
||||
if (type == 0) { |
||||
list = enprefixService.query() |
||||
.select("DISTINCT(ent_name)") |
||||
.ge("update_date", yyyyMMdd) |
||||
.le("update_date", yyyyMMddToday) |
||||
.eq("proxy_state", 4) |
||||
.list(); |
||||
} |
||||
if (CollUtil.isEmpty(list)) { |
||||
return false; |
||||
} |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
for (NbmsEnprefix enprefix : list) { |
||||
companyName = enprefix.getEntName(); |
||||
String template = companyName + "|" + startIP + "|" + endIP + "|" + position + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 五、 标识注册企业主体信息上报 |
||||
* |
||||
* @param type |
||||
* @param yyyyMMdd |
||||
* @param yyyyMMddToday |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Boolean creatFiveUpFile(Integer type, String yyyyMMdd, String yyyyMMddToday) throws IOException { |
||||
String companyCode; //标识码企业前缀
|
||||
String companyName; // 标识解析节点经营主体名称
|
||||
String level; // 标识解析系统级别
|
||||
String accessProvince; // 接入省份
|
||||
String accessCity; // 接入地市
|
||||
String registerTime; // 注册时间
|
||||
String categoryA; // 经营主体行业门类
|
||||
String categoryB; // 经营主体行业大类
|
||||
String companyType; // 公司性质
|
||||
String serviceProfession; //节点服务行业
|
||||
|
||||
List<NbmsEntApply> list = null; |
||||
// 新增操作
|
||||
if (type == 0) { |
||||
list = nbmsEntApplyServcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyType, 1) |
||||
.eq(NbmsEntApply::getApplyStep, 4) |
||||
.ge(NbmsEntApply::getUpdateDate, yyyyMMdd) |
||||
.le(NbmsEntApply::getUpdateDate, yyyyMMddToday) |
||||
.list(); |
||||
} |
||||
// 修改操作
|
||||
if (type == 1) { |
||||
list = nbmsEntApplyServcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyType, 2) |
||||
.eq(NbmsEntApply::getApplyType, 3) |
||||
.eq(NbmsEntApply::getApplyStep, 4) |
||||
.ge(NbmsEntApply::getUpdateDate, yyyyMMdd) |
||||
.le(NbmsEntApply::getUpdateDate, yyyyMMddToday) |
||||
.list(); |
||||
} |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
if (CollUtil.isNotEmpty(list)) { |
||||
for (NbmsEntApply nbmsEnapply : list) { |
||||
companyCode = nbmsEnapply.getEntPrefix(); |
||||
companyName = nbmsEnapply.getOrgName(); |
||||
// level = "4";
|
||||
accessProvince = nbmsEnapply.getOrgAddrProvince(); |
||||
accessProvince = CodeCache.codeMap.get(accessProvince); |
||||
|
||||
accessCity = nbmsEnapply.getOrgAddrCity(); |
||||
accessCity = CodeCache.codeMap.get(accessCity); |
||||
|
||||
registerTime = DateUtil.format(nbmsEnapply.getUpdateDate(), "yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
categoryA = nbmsEnapply.getIndustrySpecific(); |
||||
categoryA = CodeCache.codeMap.get(categoryA); |
||||
|
||||
categoryB = nbmsEnapply.getIndustryCategory(); |
||||
categoryB = CodeCache.codeMap.get(categoryB); |
||||
|
||||
companyType = judge(nbmsEnapply.getOrgNature()); |
||||
serviceProfession = categoryB; |
||||
|
||||
String template = companyCode + "|" + companyName + "|" + "|" + accessProvince + "|" + accessCity + "|" + registerTime + "|" + categoryA + "|" + categoryB + "|" + companyType + "|" + serviceProfession + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void creatSixUpFileAndUp(String yesterday) throws Exception { |
||||
JSch jsch = new JSch(); |
||||
Session session = jsch.getSession(Constant.user, Constant.host, 30017); |
||||
session.setPassword(Constant.password1); |
||||
session.setConfig("StrictHostKeyChecking", "no"); |
||||
session.connect(); |
||||
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp"); |
||||
sftp.connect(1000); |
||||
|
||||
// 连接远程服务器,日志存放地
|
||||
String yesterdayStr = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"); |
||||
String directoryPath = Constant.sixRemoteLogPackage + yesterdayStr; |
||||
List<String> allFile = listFiles(directoryPath, sftp); |
||||
|
||||
if (CollUtil.isEmpty(allFile)) { |
||||
XxlJobHelper.log("表4:昨日无日志文件夹!"); |
||||
return; |
||||
} |
||||
for (String filePath : allFile) { |
||||
// 读取远程服务器上的日志文件 gz压缩格式
|
||||
GZIPInputStream gzipInputStream = new GZIPInputStream(sftp.get(directoryPath + "/" + filePath)); |
||||
Reader decoder = new InputStreamReader(gzipInputStream, "UTF-8"); |
||||
BufferedReader reader = new BufferedReader(decoder); |
||||
// 创建输出流
|
||||
FileOutputStream outputStream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
String tempString; |
||||
//一次读一行,读入null时文件结束
|
||||
while ((tempString = reader.readLine()) != null) { |
||||
// 获得请求时间
|
||||
JSONObject jsonObject = JSON.parseObject(tempString); |
||||
String operatorTime = jsonObject.getString("operatorTime"); |
||||
Date date1 = DateUtil.parse(operatorTime, "yyyyMMddHHmmss"); |
||||
String requestTime = DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"); |
||||
// 获得响应时间
|
||||
String responseTime = requestTime; |
||||
// 获得源IP
|
||||
String sourceIP = jsonObject.getString("userIp"); |
||||
// 端口
|
||||
String port = "80"; |
||||
// 获得目的IP
|
||||
String destinationIP = jsonObject.getString("idisIp"); |
||||
// 方法
|
||||
String method = "HTTPM_GET"; |
||||
// 企业标识码
|
||||
String companyCode = jsonObject.getString("prefix"); |
||||
// 标识编码
|
||||
String ideCode = jsonObject.getString("handleName"); |
||||
//
|
||||
|
||||
// 组装字符串
|
||||
tempString = requestTime + "|" + responseTime + "|" + sourceIP + "|" + port + "|" + destinationIP + "|" + port + "|" + method + "|" + companyCode + "|" + ideCode + "|" + "|" + "|" + "|" + "http://code.qnaiot.com" + "|" + "http://code.qnaiot.com" + "|" + "\n"; |
||||
|
||||
byte[] bytes = tempString.getBytes(); |
||||
outputStream.write(bytes); |
||||
|
||||
} |
||||
outputStream.flush(); |
||||
outputStream.close(); |
||||
decoder.close(); |
||||
gzipInputStream.close(); |
||||
// 上传
|
||||
String fileName = Constant.localNotEncryFileNamePath; |
||||
// 要上传的目录
|
||||
String upSrc = "/004/" + yesterday; |
||||
// 表名(文件名的一部分)
|
||||
String tableName = "SDQN-basic_registered_log-"; |
||||
String operationName = ".bin"; |
||||
this.upMethod(fileName, upSrc, tableName, operationName); |
||||
} |
||||
sftp.disconnect(); |
||||
// session.disconnect();
|
||||
|
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void creatSevenUpFileAndUp(String yesterday) throws Exception { |
||||
JSch jsch = new JSch(); |
||||
Session session = jsch.getSession(Constant.user, Constant.host, 30017); |
||||
session.setPassword(Constant.password1); |
||||
session.setConfig("StrictHostKeyChecking", "no"); |
||||
session.connect(); |
||||
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp"); |
||||
sftp.connect(1000); |
||||
|
||||
// 连接远程服务器,日志存放地
|
||||
String yesterdayStr = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"); |
||||
String directoryPath = Constant.sixRemoteLogPackage + yesterdayStr; |
||||
List<String> allFile = listFiles(directoryPath, sftp); |
||||
|
||||
if (CollUtil.isEmpty(allFile)) { |
||||
XxlJobHelper.log("表4:昨日无日志文件夹!"); |
||||
return; |
||||
} |
||||
for (String filePath : allFile) { |
||||
// 读取远程服务器上的日志文件 gz压缩格式
|
||||
GZIPInputStream gzipInputStream = new GZIPInputStream(sftp.get(directoryPath + "/" + filePath)); |
||||
Reader decoder = new InputStreamReader(gzipInputStream, "UTF-8"); |
||||
BufferedReader reader = new BufferedReader(decoder); |
||||
// 创建输出流
|
||||
FileOutputStream outputStream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
String tempString; |
||||
//一次读一行,读入null时文件结束
|
||||
while ((tempString = reader.readLine()) != null) { |
||||
// 获得请求时间
|
||||
JSONObject jsonObject = JSON.parseObject(tempString); |
||||
String operatorTime = jsonObject.getString("operatorTime"); |
||||
Date date1 = DateUtil.parse(operatorTime, "yyyyMMddHHmmss"); |
||||
String requestTime = DateUtil.format(date1, "yyyy-MM-dd HH:mm:ss"); |
||||
// 获得响应时间
|
||||
String responseTime = requestTime; |
||||
// 获得源IP
|
||||
String sourceIP = jsonObject.getString("userIp"); |
||||
// 端口
|
||||
String port = "80"; |
||||
// 获得目的IP
|
||||
String destinationIP = jsonObject.getString("idisIp"); |
||||
// 方法
|
||||
String method = "HTTPM_GET"; |
||||
// 企业标识码
|
||||
String companyCode = jsonObject.getString("prefix"); |
||||
// 标识编码
|
||||
String ideCode = jsonObject.getString("handleName"); |
||||
//
|
||||
|
||||
// 组装字符串
|
||||
tempString = requestTime + "|" + responseTime + "|" + sourceIP + "|" + port + "|" + destinationIP + "|" + port + "|" + method + "|" + companyCode + "|" + ideCode + "|" + "|" + "|" + "|" + "http://code.qnaiot.com" + "|" + "http://code.qnaiot.com" + "|" + "\n"; |
||||
|
||||
byte[] bytes = tempString.getBytes(); |
||||
outputStream.write(bytes); |
||||
|
||||
} |
||||
outputStream.flush(); |
||||
outputStream.close(); |
||||
decoder.close(); |
||||
gzipInputStream.close(); |
||||
// 上传
|
||||
String fileName = Constant.localNotEncryFileNamePath; |
||||
// 要上传的目录
|
||||
String upSrc = "/005/" + yesterday; |
||||
// 表名(文件名的一部分)
|
||||
String tableName = "SDQN-basic_identification_log-"; |
||||
String operationName = ".bin"; |
||||
this.upMethod(fileName, upSrc, tableName, operationName); |
||||
} |
||||
sftp.disconnect(); |
||||
} |
||||
|
||||
|
||||
// private void deleteFile(String src) {
|
||||
//
|
||||
// System.out.println(src);
|
||||
// File file = new File( src);
|
||||
// boolean delete = file.delete();
|
||||
// System.out.println(delete);
|
||||
// }
|
||||
|
||||
private String judge(int companyType) { |
||||
//单位性质,国有控股、民营控股、外商控股、事业单位、民营非盈利
|
||||
if (companyType == 1) { |
||||
return "国有控股"; |
||||
} |
||||
if (companyType == 2) { |
||||
return "民营控股"; |
||||
} |
||||
if (companyType == 3) { |
||||
return "外商控股"; |
||||
} |
||||
if (companyType == 4) { |
||||
return "事业单位"; |
||||
} |
||||
if (companyType == 5) { |
||||
return "民营非盈利"; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 列出目录下的文件 |
||||
* |
||||
* @param directory 要列出的目录 |
||||
* @return |
||||
* @throws SftpException |
||||
* @throws JSchException |
||||
*/ |
||||
private List<String> listFiles(String directory, ChannelSftp channelSftp) { |
||||
// 显示目录信息
|
||||
Vector ls = null; |
||||
try { |
||||
ls = channelSftp.ls(directory); |
||||
} catch (SftpException e) { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
Iterator iterator = ls.iterator(); |
||||
|
||||
try { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
while (iterator.hasNext()) { |
||||
ChannelSftp.LsEntry file = (ChannelSftp.LsEntry) iterator.next(); |
||||
//文件名称
|
||||
String fileName = file.getFilename(); |
||||
//移除上级目录和根目录:"." ".."
|
||||
if (".".equals(fileName) || "..".equals(fileName)) { |
||||
continue; |
||||
} |
||||
list.add(fileName); |
||||
} |
||||
return list; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.example.ftpdemo.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.example.ftpdemo.entity.NbmsEnprefix; |
||||
import com.example.ftpdemo.mapper.NbmsEnprefixMapper; |
||||
import com.example.ftpdemo.service.NbmsEnprefixService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Service |
||||
public class NbmsEnprefixServiceImpl extends ServiceImpl<NbmsEnprefixMapper, NbmsEnprefix> implements NbmsEnprefixService { |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.example.ftpdemo.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.example.ftpdemo.entity.NbmsEntApply; |
||||
import com.example.ftpdemo.mapper.NbmsEntApplyMapper; |
||||
import com.example.ftpdemo.service.NbmsEntApplyServcie; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Service |
||||
public class NbmsEntApplyServcieImpl extends ServiceImpl<NbmsEntApplyMapper, NbmsEntApply> implements NbmsEntApplyServcie { |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.example.ftpdemo.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.example.ftpdemo.entity.NbmsEnt; |
||||
import com.example.ftpdemo.mapper.NbmsEntMapper; |
||||
import com.example.ftpdemo.service.NbmsEntServcie; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Service |
||||
public class NbmsEntServiceImpl extends ServiceImpl<NbmsEntMapper, NbmsEnt> implements NbmsEntServcie { |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.example.ftpdemo.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.example.ftpdemo.entity.SysDict; |
||||
import com.example.ftpdemo.mapper.SysDictMapper; |
||||
import com.example.ftpdemo.service.SysDictService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/28 |
||||
*/ |
||||
@Service |
||||
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService { |
||||
@Override |
||||
public List<SysDict> selectAll() { |
||||
List<SysDict> list = baseMapper.selectList(null); |
||||
return list; |
||||
} |
||||
} |
@ -0,0 +1,215 @@
|
||||
package com.example.ftpdemo.task; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.example.ftpdemo.service.Method; |
||||
import com.example.ftpdemo.service.NbmsEntApplyServcie; |
||||
import com.example.ftpdemo.util.Constant; |
||||
import com.xxl.job.core.context.XxlJobHelper; |
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StopWatch; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 三、 标识解析企业主体信息上报 |
||||
* |
||||
* @author laifeng |
||||
* @since 2022/11/29 |
||||
*/ |
||||
@Component |
||||
@AllArgsConstructor |
||||
public class IdentificationUpTask { |
||||
private final NbmsEntApplyServcie nbmsEntApplyServcie; |
||||
private final Method method; |
||||
|
||||
// @Scheduled(cron = "0/20 * * * * ? ")
|
||||
@XxlJob("demoJobTest") |
||||
public void refreshAliDeviceStatus() { |
||||
StopWatch stopWatch = new StopWatch("task"); |
||||
stopWatch.start(); |
||||
// 标识解析企业主体信息上报检测新增并上传
|
||||
threePackMethod(0); |
||||
// 标识解析企业主体信息上报检测更新并上传
|
||||
threePackMethod(1); |
||||
|
||||
fourPackMethod(0); |
||||
fourPackMethod(1); |
||||
|
||||
fivePackMethod(0); |
||||
fivePackMethod(1); |
||||
|
||||
String yesterday = DateUtil.format(DateUtil.yesterday(), "yyyyMMdd"); |
||||
// 注册数据上报
|
||||
try { |
||||
method.creatSixUpFileAndUp(yesterday); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
// 解析数据上报
|
||||
try { |
||||
method.creatSevenUpFileAndUp(yesterday); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
stopWatch.stop(); |
||||
double seconds = stopWatch.getTotalTimeSeconds(); |
||||
XxlJobHelper.log("XXL-JOB, 上传日志成功! 共花费:" + seconds); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 三、 标识解析企业主体信息上报 |
||||
* |
||||
* @param type 0 新增 1 更新 |
||||
*/ |
||||
private void threePackMethod(Integer type) { |
||||
// 时间格式化
|
||||
Date date = DateUtil.yesterday(); |
||||
String yyyyMMdd = DateUtil.format(date, "yyyyMMdd"); |
||||
String yyyyMMddToday = DateUtil.format(DateUtil.date(), "yyyyMMdd"); |
||||
Boolean temp = false; |
||||
|
||||
try { |
||||
temp = method.creatIdentificationUpFile(type, yyyyMMdd, yyyyMMddToday); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
// 如果没有生成文件,可直接结束
|
||||
if (!temp) { |
||||
String logName =""; |
||||
if (type==0){ |
||||
logName ="新增"; |
||||
}else { |
||||
logName ="更新"; |
||||
} |
||||
XxlJobHelper.log("表1:昨日无"+logName+"数据日志!"); |
||||
return; |
||||
} |
||||
|
||||
|
||||
String fileName = Constant.localNotEncryFileNamePath; |
||||
// 要上传的目录
|
||||
String upSrc = "/001/" + yyyyMMdd; |
||||
// 表名(文件名的一部分)
|
||||
String tableName = "SDQN-basic_identification-"; |
||||
String operationName = ""; |
||||
if (type == 0) { |
||||
// 操作类型为新增
|
||||
operationName = "-add.bin"; |
||||
} |
||||
if (type == 1) { |
||||
// 操作类型为更新
|
||||
operationName = "-update.bin"; |
||||
} |
||||
try { |
||||
method.upMethod(fileName, upSrc, tableName, operationName); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 四、 标识解析企业主体信息上报 |
||||
* |
||||
* @param type 0 新增 1 更新 |
||||
*/ |
||||
private void fourPackMethod(Integer type) { |
||||
// 时间格式化
|
||||
Date date = DateUtil.yesterday(); |
||||
String yyyyMMdd = DateUtil.format(date, "yyyyMMdd"); |
||||
String yyyyMMddToday = DateUtil.format(DateUtil.date(), "yyyyMMdd"); |
||||
Boolean temp = false; |
||||
|
||||
try { |
||||
temp = method.creatForUpFile(type, yyyyMMdd, yyyyMMddToday); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
// 如果没有生成文件,可直接结束
|
||||
if (!temp) { |
||||
String logName =""; |
||||
if (type==0){ |
||||
logName ="新增"; |
||||
}else { |
||||
logName ="更新"; |
||||
} |
||||
XxlJobHelper.log("表2:昨日无"+logName+"数据日志!"); |
||||
return; |
||||
} |
||||
|
||||
String fileName = Constant.localNotEncryFileNamePath; |
||||
// 要上传的目录
|
||||
String upSrc = "/002/" + yyyyMMdd; |
||||
// 表名(文件名的一部分)
|
||||
String tableName = "SDQN-basic_identification_ip-"; |
||||
String operationName = ""; |
||||
if (type == 0) { |
||||
// 操作类型为新增
|
||||
operationName = "-add.bin"; |
||||
} |
||||
if (type == 1) { |
||||
// 操作类型为更新
|
||||
operationName = "-update.bin"; |
||||
} |
||||
try { |
||||
method.upMethod(fileName, upSrc, tableName, operationName); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 五、 标识注册企业主体信息上报 |
||||
* |
||||
* @param type |
||||
*/ |
||||
private void fivePackMethod(Integer type) { |
||||
// 时间格式化
|
||||
Date date = DateUtil.yesterday(); |
||||
String yyyyMMdd = DateUtil.format(date, "yyyyMMdd"); |
||||
String yyyyMMddToday = DateUtil.format(DateUtil.date(), "yyyyMMdd"); |
||||
Boolean temp = false; |
||||
|
||||
try { |
||||
temp = method.creatFiveUpFile(type, yyyyMMdd, yyyyMMddToday); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
// 如果没有生成文件,可直接结束
|
||||
if (!temp) { |
||||
String logName =""; |
||||
if (type==0){ |
||||
logName ="新增"; |
||||
}else { |
||||
logName ="更新"; |
||||
} |
||||
XxlJobHelper.log("表3:昨日无"+logName+"数据日志!"); |
||||
return; |
||||
} |
||||
|
||||
|
||||
String fileName = Constant.localNotEncryFileNamePath; |
||||
// 要上传的目录
|
||||
String upSrc = "/003/" + yyyyMMdd; |
||||
// 表名(文件名的一部分)
|
||||
String tableName = "SDQN-basic_registered-"; |
||||
String operationName = ""; |
||||
if (type == 0) { |
||||
// 操作类型为新增
|
||||
operationName = "-add.bin"; |
||||
} |
||||
if (type == 1) { |
||||
// 操作类型为更新
|
||||
operationName = "-update.bin"; |
||||
} |
||||
try { |
||||
method.upMethod(fileName, upSrc, tableName, operationName); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.example.ftpdemo.task; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.example.ftpdemo.service.Method; |
||||
import com.xxl.job.core.context.XxlJobHelper; |
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StopWatch; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/12/1 |
||||
*/ |
||||
@Component |
||||
@AllArgsConstructor |
||||
public class TestTask { |
||||
private final Method method; |
||||
|
||||
@XxlJob("demoJobHandler") |
||||
public void refreshAliDeviceStatus() throws Exception { |
||||
StopWatch stopWatch = new StopWatch("task"); |
||||
stopWatch.start(); |
||||
String yesterday = DateUtil.format(DateUtil.yesterday(), "yyyyMMdd"); |
||||
method.creatSixUpFileAndUp(yesterday); |
||||
stopWatch.stop(); |
||||
double seconds = stopWatch.getTotalTimeSeconds(); |
||||
XxlJobHelper.log("XXL-JOB, 上传日志成功! 共花费:" + seconds); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.example.ftpdemo.task; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.example.ftpdemo.service.Method; |
||||
import com.xxl.job.core.context.XxlJobHelper; |
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StopWatch; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/12/1 |
||||
*/ |
||||
@Component |
||||
@EnableScheduling |
||||
@AllArgsConstructor |
||||
public class TestTask1 { |
||||
private final Method method; |
||||
|
||||
// @XxlJob("demoJobTest")
|
||||
// @Scheduled(cron = "0/10 * * * * ? ")
|
||||
public void refreshAliDeviceStatus() throws Exception { |
||||
String format = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"); |
||||
System.out.println(format); |
||||
XxlJobHelper.log("XXL-JOB,测试" ,format); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.example.ftpdemo.util; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/27 |
||||
*/ |
||||
public interface Constant { |
||||
String ipAddress = "123.233.115.26";// ip地址
|
||||
String userName = "qingniao";// 账号
|
||||
String password = "SDguzRp";// 密码
|
||||
|
||||
// String ipAddress = "47.97.5.58";// ip地址
|
||||
// String userName = "root";// 账号
|
||||
// String password = "Aa1572427111.";// 密码
|
||||
|
||||
String host = "223.99.228.240";// ip地址
|
||||
String user = "root";// 账号
|
||||
String password1 = "Qingniao@123!";// 密码
|
||||
|
||||
// 表6 本地文件生成地址
|
||||
String localNotEncryFileNamePath = "/opt/uplog/test.txt"; |
||||
|
||||
// 生成zip文件地址
|
||||
String zipPath = "/opt/uplog"; |
||||
|
||||
// 生成本地文件地址:目录 加密(服务器地址需要修改)
|
||||
String localPackage = "/opt/uplog/"; |
||||
|
||||
//
|
||||
String sixRemoteLogPackage = "/opt/idhub/logs/idhub-idis/oplog/"; |
||||
} |
@ -0,0 +1,33 @@
|
||||
server: |
||||
port: 1572 |
||||
spring: |
||||
datasource: |
||||
# username: idis_user |
||||
# password: Teleinfo-88 |
||||
# url: jdbc:mysql://223.99.228.240:3306/snms?characterEncoding=utf8&useSSL=false&serverTimezone=UTC |
||||
username: root |
||||
password: Qn12345@ |
||||
url: jdbc:mysql://223.99.197.190:13306/bladex_boot?characterEncoding=utf8&useSSL=false&serverTimezone=UTC |
||||
driver-class-name: com.mysql.cj.jdbc.Driver |
||||
#223.99.197.190:13306 |
||||
|
||||
# job执行器配置 |
||||
xxl: |
||||
job: |
||||
enabled: true |
||||
executor: |
||||
appname: xxl-job-sample-local |
||||
address: |
||||
ip: |
||||
port: 9999 |
||||
logpath: /opt/xxldata |
||||
logretentiondays: 30 |
||||
accessToken: default_token |
||||
admin: |
||||
addresses: http://47.97.5.58:8080/xxl-job-admin |
||||
|
||||
logging: |
||||
config: classpath:logback.xml |
||||
level: |
||||
root: info |
||||
|
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration debug="false" scan="true" scanPeriod="1 seconds"> |
||||
|
||||
<contextName>logback</contextName> |
||||
<property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-springboot.log"/> |
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<file>${log.path}</file> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n |
||||
</pattern> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<root level="info"> |
||||
<appender-ref ref="console"/> |
||||
<appender-ref ref="file"/> |
||||
</root> |
||||
|
||||
</configuration> |
@ -0,0 +1,180 @@
|
||||
package com.example.ftpdemo; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.example.ftpdemo.cache.CodeCache; |
||||
import com.example.ftpdemo.entity.NbmsEnprefix; |
||||
import com.example.ftpdemo.entity.NbmsEntApply; |
||||
import com.example.ftpdemo.service.NbmsEnprefixService; |
||||
import com.example.ftpdemo.service.NbmsEntApplyServcie; |
||||
import com.example.ftpdemo.util.Decrypt; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
@SpringBootTest |
||||
class FtpDemoApplicationTests { |
||||
|
||||
|
||||
String companyCode; //标识码企业前缀
|
||||
String companyName; // 标识解析节点经营主体名称
|
||||
String level; // 标识解析系统级别
|
||||
String accessProvince; // 接入省份
|
||||
String accessCity; // 接入地市
|
||||
String registerTime; // 注册时间
|
||||
String categoryA; // 经营主体行业门类
|
||||
String categoryB; // 经营主体行业大类
|
||||
String companyType; // 公司性质
|
||||
String serviceProfession; //节点服务行业
|
||||
String startIP = "223.99.228.240"; |
||||
String endIP = "223.99.228.240"; |
||||
String position = "中国山东省济南市自由贸易试验区济南片区颖秀路2299号"; |
||||
@Autowired |
||||
private NbmsEntApplyServcie servcie; |
||||
@Autowired |
||||
private NbmsEnprefixService enprefixService; |
||||
|
||||
|
||||
@Test |
||||
void contextLoads() throws IOException { |
||||
// 生成文件
|
||||
|
||||
List<NbmsEntApply> list = servcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyType, 1) |
||||
.list(); |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream("d://aaa//test.txt"); |
||||
for (NbmsEntApply nbmsEnapply : list) { |
||||
companyCode = nbmsEnapply.getEntPrefix(); |
||||
companyName = nbmsEnapply.getOrgName(); |
||||
level = "4"; |
||||
accessProvince = nbmsEnapply.getOrgAddrProvince(); |
||||
accessProvince = CodeCache.codeMap.get(accessProvince); |
||||
|
||||
accessCity = nbmsEnapply.getOrgAddrCity(); |
||||
accessCity = CodeCache.codeMap.get(accessCity); |
||||
|
||||
registerTime = DateUtil.format(nbmsEnapply.getUpdateDate(), "yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
categoryA = nbmsEnapply.getIndustrySpecific(); |
||||
categoryA = CodeCache.codeMap.get(categoryA); |
||||
|
||||
categoryB = nbmsEnapply.getIndustryCategory(); |
||||
categoryB = CodeCache.codeMap.get(categoryB); |
||||
|
||||
companyType = judge(nbmsEnapply.getOrgNature()); |
||||
serviceProfession = categoryB; |
||||
|
||||
String template = companyCode + "|" + companyName + "|" + level + "|" + accessProvince + "|" + accessCity + "|" + registerTime + "|" + categoryA + "|" + categoryB + "|" + companyType + "|" + serviceProfession + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
System.out.println("完成!!!"); |
||||
} |
||||
|
||||
@Test |
||||
void test1() throws IOException { |
||||
List<NbmsEnprefix> list = enprefixService.query() |
||||
.select("DISTINCT(ent_name)") |
||||
.eq("proxy_state", 4) |
||||
.list(); |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream("D://aaa//test.txt"); |
||||
for (NbmsEnprefix enprefix : list) { |
||||
companyName = enprefix.getEntName(); |
||||
String template = companyName + "|" + startIP + "|" + endIP + "|" + position + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
} |
||||
|
||||
@Test |
||||
void five() throws IOException { |
||||
// 生成文件
|
||||
|
||||
List<NbmsEntApply> list = servcie.lambdaQuery().eq(NbmsEntApply::getFirstAuditStatus, 2) |
||||
.eq(NbmsEntApply::getApplyStep, 4) |
||||
.eq(NbmsEntApply::getApplyType, 1) |
||||
.list(); |
||||
// 创建输出流
|
||||
FileOutputStream stream = new FileOutputStream("d://aaa//test.txt"); |
||||
for (NbmsEntApply nbmsEnapply : list) { |
||||
companyCode = nbmsEnapply.getEntPrefix(); |
||||
companyName = nbmsEnapply.getOrgName(); |
||||
// level = "4";
|
||||
accessProvince = nbmsEnapply.getOrgAddrProvince(); |
||||
accessProvince = CodeCache.codeMap.get(accessProvince); |
||||
|
||||
accessCity = nbmsEnapply.getOrgAddrCity(); |
||||
accessCity = CodeCache.codeMap.get(accessCity); |
||||
|
||||
registerTime = DateUtil.format(nbmsEnapply.getUpdateDate(), "yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
categoryA = nbmsEnapply.getIndustrySpecific(); |
||||
categoryA = CodeCache.codeMap.get(categoryA); |
||||
|
||||
categoryB = nbmsEnapply.getIndustryCategory(); |
||||
categoryB = CodeCache.codeMap.get(categoryB); |
||||
|
||||
companyType = judge(nbmsEnapply.getOrgNature()); |
||||
serviceProfession = categoryB; |
||||
|
||||
String template = companyCode + "|" + companyName + "|" + accessProvince + "|" + accessCity + "|" + registerTime + "|" + categoryA + "|" + categoryB + "|" + companyType + "|" + serviceProfession + "\n"; |
||||
byte[] bytes = template.getBytes(); |
||||
stream.write(bytes); |
||||
} |
||||
stream.flush(); |
||||
stream.close(); |
||||
System.out.println("完成!!!"); |
||||
} |
||||
|
||||
@Test |
||||
void test33(){ |
||||
Decrypt.readFileByLines("C:\\Users\\Reborn\\Desktop\\fsdownload\\88.100_2022-11-10_7301f27a6a92497c86d19ba578e81c83_c1cd57d4f4406a28773e664170073d25.gz"); |
||||
// List<File> allFile = Decrypt.getAllFile("C:\\Users\\Reborn\\Desktop\\fsdownload");
|
||||
// for (File file : allFile) {
|
||||
// System.out.println(file);
|
||||
// }
|
||||
} |
||||
|
||||
|
||||
@Test |
||||
void deleTest(){ |
||||
File file = new File("D:\\aaa\\SDQN-basic_registered-1669779364902-all.bin"); |
||||
System.out.println(file); |
||||
boolean delete = file.delete(); |
||||
System.out.println(delete); |
||||
|
||||
} |
||||
|
||||
private String judge(int companyType) { |
||||
//单位性质,国有控股、民营控股、外商控股、事业单位、民营非盈利
|
||||
if (companyType == 1) { |
||||
return "国有控股"; |
||||
} |
||||
if (companyType == 2) { |
||||
return "民营控股"; |
||||
} |
||||
if (companyType == 3) { |
||||
return "外商控股"; |
||||
} |
||||
if (companyType == 4) { |
||||
return "事业单位"; |
||||
} |
||||
if (companyType == 5) { |
||||
return "民营非盈利"; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,58 @@
|
||||
package com.example.ftpdemo; |
||||
|
||||
import com.example.ftpdemo.util.Constant; |
||||
import com.jcraft.jsch.*; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.io.*; |
||||
import java.util.zip.GZIPInputStream; |
||||
|
||||
/** |
||||
* @author laifeng |
||||
* @since 2022/11/30 |
||||
*/ |
||||
public class TestMethod { |
||||
String host = "47.97.5.58";// ip地址
|
||||
String user = "root";// 账号
|
||||
String password = "Aa1572427111.";// 密码
|
||||
@Test |
||||
void test1() throws JSchException, IOException, SftpException { |
||||
JSch jsch=new JSch(); |
||||
Session session=jsch.getSession(user, host, 22); |
||||
session.setPassword(password); |
||||
session.setConfig("StrictHostKeyChecking", "no"); |
||||
session.connect(); |
||||
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp"); |
||||
sftp.connect(); |
||||
|
||||
|
||||
String file = "/opt/2022-11-29~0.log.21-29-58_541.time.43.part.complete.gz"; |
||||
|
||||
|
||||
|
||||
// 读取远程服务器上的日志文件 gz压缩格式
|
||||
GZIPInputStream gzipInputStream = new GZIPInputStream(sftp.get(file)); |
||||
Reader decoder = new InputStreamReader(gzipInputStream, "UTF-8"); |
||||
BufferedReader reader = new BufferedReader(decoder); |
||||
// 创建输出流
|
||||
FileOutputStream outputStream = new FileOutputStream(Constant.localNotEncryFileNamePath); |
||||
String tempString; |
||||
//一次读一行,读入null时文件结束
|
||||
while ((tempString = reader.readLine()) != null) { |
||||
//把当前行号显示出来
|
||||
// System.out.println(tempString);
|
||||
String temp = tempString+"\n"; |
||||
byte[] bytes = temp.getBytes(); |
||||
outputStream.write(bytes); |
||||
} |
||||
outputStream.flush(); |
||||
|
||||
outputStream.close(); |
||||
decoder.close(); |
||||
sftp.disconnect(); |
||||
session.disconnect(); |
||||
|
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue