Commit 325c986c by fuwenlei

萌蒂定时任务

parents
#!/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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
echo $MAVEN_PROJECTBASEDIR
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.byit</groupId>
<artifactId>mdjob</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>md-job</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
<dependency>
<groupId>com.byit</groupId>
<artifactId>PaperlessClient</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency>
<!-- tableauHyper -->
<dependency>
<groupId>com.byit</groupId>
<artifactId>tableaucommon</artifactId>
<version>10.5</version>
</dependency>
<dependency>
<groupId>com.byit</groupId>
<artifactId>tableauhyperextract</artifactId>
<version>10.5</version>
</dependency>
<dependency>
<groupId>com.byit</groupId>
<artifactId>tableauserver</artifactId>
<version>10.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.byit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class MdJobApplication {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(MdJobApplication.class);
springApplication.run(MdJobApplication.class, args);
}
}
package com.byit.hyper;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.springframework.stereotype.Component;
import com.byit.utils.PropertiesUtil;
/**
* 链接mysql数据库
* @author
*/
@Component
public class OracleDbManager {
/**
* 获取Connection
*
* @return
* @throws SQLException
* @throws ClassNotFoundException
*/
static {
try {
//Class.forName(classForName);
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("加载Mysql数据库驱动失败!");
}
}
public static Connection getConnection() throws SQLException, IOException {
Connection conn = null;
//获取数据库信息
String url = PropertiesUtil.getValue(null, "spring.datasource.url");
String userName = PropertiesUtil.getValue(null, "spring.datasource.username");
String password = PropertiesUtil.getValue(null, "spring.datasource.password");
try {
conn = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
throw e;
}
return conn;
}
/**
* 关闭ResultSet
* @param rs
*/
public static void closeResultSet(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
/**
* 关闭Statement
* @param stmt
*/
public static void closeStatement(Statement stmt) {
if (stmt != null) {
try {
stmt.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
/**
* 关闭ResultSet、Statement
* @param rs
* @param stmt
*/
public static void closeStatement(ResultSet rs, Statement stmt) {
closeResultSet(rs);
closeStatement(stmt);
}
/**
* 关闭PreparedStatement
* @param pstmt
* @throws SQLException
*/
public static void fastcloseStmt(PreparedStatement pstmt) throws SQLException
{
pstmt.close();
}
/**
* 关闭ResultSet、PreparedStatement
* @param rs
* @param pstmt
* @throws SQLException
*/
public static void fastcloseStmt(ResultSet rs, PreparedStatement pstmt) throws SQLException
{
rs.close();
pstmt.close();
}
/**
* 关闭ResultSet、Statement、Connection
* @param rs
* @param stmt
* @param con
*/
public static void closeConnection(ResultSet rs, Statement stmt, Connection con) {
closeResultSet(rs);
closeStatement(stmt);
closeConnection(con);
}
/**
* 关闭Statement、Connection
* @param stmt
* @param con
*/
public static void closeConnection(Statement stmt, Connection con) {
closeStatement(stmt);
closeConnection(con);
}
/**
* 关闭Connection
* @param con
*/
public static void closeConnection(Connection con) {
if (con != null) {
try {
con.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
package com.byit.job.scheduler;
import java.util.List;
import java.util.Map;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.byit.utils.DecompressionFileZipUtl;
import com.byit.utils.HttpClient;
import com.byit.utils.HyperSqlMap;
@Component
public class SchedulerJob {
@Scheduled(cron = "0 * * * * ?")
// @Scheduled(cron = "0 0 0/1 * * ?")
public void upLoadReportByPositionIdScheduler() throws Exception {
long a = System.currentTimeMillis();
System.out.println("开始时间:"+a);
// 获取岗位id的json字符串数组
String doGet = HttpClient.doGet("http://10.0.103.193:8080/portal/queryserve/queryPositionIdAndUserCode.do");
// json串转化成list
Map<String,Object> map= JSONObject.parseObject(doGet);
//获取岗位数据
List<String> positionIdList = (List<String>) map.get("postionids");
// 循环获取岗位等级为1.2.3.4的岗位编号集合。
for (String position:positionIdList) {
HyperSqlMap.position_code = new String(position.getBytes("gbk"),"UTF-8");
DecompressionFileZipUtl.checkFile("D:\\test", "");
}
//获取人员编号
List<String> userCodeList = (List<String>) map.get("usercodes");
// 循环获取岗位等级为1.2.3.4的岗位编号集合。
for (String userCode:userCodeList) {
HyperSqlMap.empl_code=userCode;
DecompressionFileZipUtl.checkFile("D:\\test", "");
}
//DecompressionFileZipUtl.checkFile("D:\\test", "");
System.out.println("结束时间:"+(System.currentTimeMillis()-a)/24/60/60/1000);
}
/**
* list转字符串
*
* @param posList
* @return
*/
private String listToString(List<String> posList) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < posList.size(); i++) {
if (i == posList.size() - 1) {
sb.append("'" + posList.get(i) + "'");
} else {
sb.append("'" + posList.get(i) + "'" + ",");
}
}
return sb.toString();
}
}
package com.byit.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 压缩算法类
* 实现文件压缩,文件夹压缩,以及文件和文件夹的混合压缩
* @author ljheee
*
*/
public class CompressedFileZipUtil {
/**
* 完成的结果文件--输出的压缩文件
*/
File targetFile;
public CompressedFileZipUtil() {}
public CompressedFileZipUtil(File target) {
targetFile = target;
if (targetFile.exists())
targetFile.delete();
}
/**
* 压缩文件
*
* @param srcfile
*/
public void zipFiles(File srcfile) {
ZipOutputStream out = null;
try {
out = new ZipOutputStream(new FileOutputStream(targetFile));
if(srcfile.isFile()){
zipFile(srcfile, out, "");
} else{
File[] list = srcfile.listFiles();
for (int i = 0; i < list.length; i++) {
compress(list[i], out, "");
}
}
System.out.println("压缩完毕");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 压缩文件夹里的文件
* 起初不知道是文件还是文件夹--- 统一调用该方法
* @param file
* @param out
* @param basedir
*/
private void compress(File file, ZipOutputStream out, String basedir) {
/* 判断是目录还是文件 */
if (file.isDirectory()) {
this.zipDirectory(file, out, basedir);
} else {
this.zipFile(file, out, basedir);
}
}
/**
* 压缩单个文件
*
* @param srcfile
*/
public void zipFile(File srcfile, ZipOutputStream out, String basedir) {
if (!srcfile.exists())
return;
byte[] buf = new byte[1024];
FileInputStream in = null;
try {
int len;
in = new FileInputStream(srcfile);
out.putNextEntry(new ZipEntry(basedir + srcfile.getName()));
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.closeEntry();
if (in != null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 压缩文件夹
* @param dir
* @param out
* @param basedir
*/
public void zipDirectory(File dir, ZipOutputStream out, String basedir) {
if (!dir.exists())
return;
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
/* 递归 */
compress(files[i], out, basedir + dir.getName() + "/");
}
}
/*//测试
public static void main(String[] args) {
File f = new File("D:/test/test");
new CompactAlgorithm(new File( "E:/",f.getName()+".zip")).zipFiles(f);
}*/
}
package com.byit.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
/***
*
* @param date
* @param dateFormat
* : e.g:yyyy-MM-dd HH:mm:ss
* @return
*/
public static String formatDateByPattern(Date date, String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
String formatTimeStr = null;
if (date != null) {
formatTimeStr = sdf.format(date);
}
return formatTimeStr;
}
/***
* convert Date to cron ,eg. "0 06 10 15 1 ? 2014"
*
* @param date
* : 时间点
* @return
*/
public static String getCron(java.util.Date date) {
String dateFormat = "ss mm HH dd MM ? yyyy";
return formatDateByPattern(date, dateFormat);
}
/**
* cron表达式转为日期
*
* @param cron
* @return
*/
public static Date getCronToDate(String cron) {
String dateFormat = "ss mm HH dd MM ? yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date = null;
try {
date = sdf.parse(cron);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
}
package com.byit.utils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.byit.hyper.CreateTableAuFile;
import cfca.paperless.client.util.StringUtil;
public class DecompressionFileZipUtl {
private static final int buffer = 10240;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String path = "D:\\test";
checkFile(path, "");
}
/**
* 1.将.twbx文件后缀名改为.zip 2.将zip文件解压 3.替换zip文件夹中的数据文件 4.将文件进行压缩 5.修改后缀名为twbx
*
* @throws Exception
*/
public static void checkFile(String filePath, String zipName) throws Exception {
File file = new File(filePath);
File[] fileArr = file.listFiles();
// 判断文件夹是否为空
if (fileArr.length > 0) {
// 循环读取文件
for (File files : fileArr) {
// 判断文件名字是否为.twbx结尾文件
String name = files.getName();
if (name.endsWith(".twbx")) {
zipName = "";
if (StringUtil.isEmpty(zipName)) {
zipName = name.substring(0, name.indexOf(".twbx"));
}
String newPath = filePath + System.getProperty("file.separator")
+ name.substring(0, name.indexOf(".twbx")) + ".zip";
files.renameTo(new File(newPath));
// 调用解压文件
unZip(newPath);
nextFile(filePath + System.getProperty("file.separator") + zipName
+ System.getProperty("file.separator") + "Data" + System.getProperty("file.separator"),
zipName);
}
}
}
}
/**
* 查询解压文件下的文件夹
* @throws Exception
* */
public static void nextFile(String filePath,String zipName) throws Exception{
boolean flag = false;
File file = new File(filePath);
File[] fileArr = file.listFiles();
// 判断文件夹是否为空
if (null!=fileArr&&fileArr.length > 0) {
// 循环读取文件
for (File files : fileArr) {
//判断是否为文件夹
if(files.isDirectory()){
nextFile(filePath+files.getName(),zipName);
}else{
// 判断文件名字是否为.twbx结尾文件
String name = files.getName();
// 判断hyper文件名称
if (name.endsWith(".hyper")) {
flag = true;
// 获取文件得名字
String hyperName = name.substring(0, name.indexOf(".hyper"));
// 调用根据文件名字调用枚举类查询sql
HyperSqlMap hyper = new HyperSqlMap();
String sql = hyper.hyperSqlMap.get(hyperName).toString();
// 查询数据并写入hyper文件 并返还路径
CreateTableAuFile createTableAuFile = new CreateTableAuFile();
String newHyperName = createTableAuFile.createFile("D:\\", sql, hyperName);
//String newHyperName = "D:\\"+name;
// 复制文件并替换源文件
copyFile(newHyperName, filePath + System.getProperty("file.separator") + name);
}
}
}
if(flag){
//filePath + System.getProperty("file.separator")
// 压缩文件的路径
File f = new File( "D:\\test\\"+ zipName);
// 压缩文件twbx文件名称
String twbxName = f.getName() + ".zip";
//new CompressedFileZipUtil(new File(filePath, twbxName)).zipFiles(f);
new CompressedFileZipUtil(new File("D:\\test\\", twbxName)).zipFiles(f);
// 读取压缩文件
String zipPath ="D:\\test" + System.getProperty("file.separator");
f = new File(zipPath+twbxName);
// 获取系统时间
SimpleDateFormat sim = new SimpleDateFormat("YYYY-MM");
// 修改压缩文件后缀名
twbxName = twbxName.substring(0, twbxName.indexOf(".zip")) + ".twbx";
String newPath = zipPath+twbxName;
f.renameTo(new File(newPath));
// 根据岗位编号创建目录
File postFile = new File("F:\\test" + System.getProperty("file.separator") + System.getProperty("file.separator") + HyperSqlMap.position_code);
if (!postFile.exists()) {
postFile.mkdir();
}
//文件重命名
String postCodeName = twbxName.substring(0, twbxName.indexOf(".twbx")) + sim.format(new Date())+".twbx";
// copy压缩文件
copyFile(zipPath+twbxName,
"F:\\test" + System.getProperty("file.separator")+HyperSqlMap.position_code+ System.getProperty("file.separator") + postCodeName);
// 删除解压文件生成的目录及文件
delAllFile("D:\\test\\");
}
}
}
/**
* 解压zip文件
*/
public static void unZip(String path) {
int count = -1;
String savepath = "";
File file = null;
InputStream is = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
savepath = path.substring(0, path.lastIndexOf(".")) + File.separator; // 保存解压文件目录
new File(savepath).mkdir(); // 创建保存目录
ZipFile zipFile = null;
try {
zipFile = new ZipFile(path); // 解决中文乱码问题
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
byte buf[] = new byte[buffer];
ZipEntry entry = (ZipEntry) entries.nextElement();
String filename = entry.getName();
boolean ismkdir = false;
if (filename.lastIndexOf("/") != -1) { // 检查此文件是否带有文件夹
ismkdir = true;
}
filename = savepath + filename;
if (entry.isDirectory()) { // 如果是文件夹先创建
file = new File(filename);
file.mkdirs();
continue;
}
file = new File(filename);
if (!file.exists()) { // 如果是目录先创建
if (ismkdir) {
new File(filename.substring(0, filename.lastIndexOf("/"))).mkdirs(); // 目录先创建
}
}
file.createNewFile(); // 创建文件
is = zipFile.getInputStream(entry);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos, buffer);
while ((count = is.read(buf)) > -1) {
bos.write(buf, 0, count);
}
bos.flush();
bos.close();
fos.close();
is.close();
}
zipFile.close();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
if (is != null) {
is.close();
}
if (zipFile != null) {
zipFile.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 替换数据文件
*/
public static void copyFile(String oldPath, String newPath) {
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { // 文件存在时
InputStream inStream = new FileInputStream(oldPath); // 读入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffers = new byte[buffer];
while ((byteread = inStream.read(buffers)) != -1) {
bytesum += byteread; // 字节数 文件大小
System.out.println(bytesum);
fs.write(buffers, 0, byteread);
}
inStream.close();
fs.close();
}
} catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();
}
}
/**
* 删除文件夹下所有文件
*/
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
if (!temp.getName().endsWith(".twbx")) {
temp.delete();
}
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);// 再删除空文件夹
flag = true;
}
}
return flag;
}
/**
* 删除空文件夹
*/
public static void delFolder(String folderPath) {
try {
delAllFile(folderPath); // 删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); // 删除空文件夹
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.byit.utils;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.http.entity.ContentType;
/**
* 普通HttpClient调用工具类
*
* @author ZhouGuoJun
*
*/
public class HttpClient {
private static final Logger logger = LoggerFactory.getLogger(HttpClient.class);
/**
*
* @param url
* @param param
* @param conf
* @return
* @throws Exception
*/
public static String doGet(String url, Map<String, String> param, RequestConfig conf) throws Exception {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String result = null;
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet())
builder.addParameter(key, param.get(key));
}
URI uri = builder.build();
// 创建http GET请求
HttpGet get = new HttpGet(uri);
// 设置请求和传输超时时间
if (conf != null)
get.setConfig(conf);
// 执行请求
response = httpclient.execute(get);
result = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
} finally {
if (response != null)
response.close();
if (httpclient != null)
httpclient.close();
}
return result;
}
/**
*
* @param url
* @param conf
* @return
* @throws Exception
*/
public static String doGet(String url, RequestConfig conf) throws Exception {
return doGet(url, null, conf);
}
/**
*
* @param url
* @return
* @throws Exception
*/
public static String doGet(String url) throws Exception {
return doGet(url, null);
}
/**
*
* @param url
* @param param
* @param conf
* @return
* @throws Exception
*/
public static String doPost(String url, Map<String, String> param, RequestConfig conf) throws Exception {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String result = null;
try {
// 创建Http Post请求
HttpPost post = new HttpPost(url);
// 设置请求和传输超时时间
if (conf != null)
post.setConfig(conf);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet())
paramList.add(new BasicNameValuePair(key, param.get(key)));
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
post.setEntity(entity);
}
// 执行http请求
response = httpclient.execute(post);
result = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
} finally {
if (response != null)
response.close();
if (httpclient != null)
httpclient.close();
}
return result;
}
/**
*
* @param url
* @param conf
* @return
* @throws Exception
*/
public static String doPost(String url, RequestConfig conf) throws Exception {
return doPost(url, null, conf);
}
/**
*
* @param url
* @return
* @throws Exception
*/
public static String doPost(String url) throws Exception {
return doPost(url, null);
}
/**
*
* @param url
* @param json
* @param conf
* @return
* @throws Exception
*/
public static String doPostJson(String url, String json, RequestConfig conf) throws Exception {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String result = null;
try {
// 创建Http Post请求
HttpPost post = new HttpPost(url);
// 设置请求和传输超时时间
if (conf != null)
post.setConfig(conf);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
post.setEntity(entity);
// 执行http请求
response = httpclient.execute(post);
result = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
} finally {
if (response != null)
response.close();
if (httpclient != null)
httpclient.close();
}
return result;
}
}
package com.byit.utils;
import java.util.HashMap;
import java.util.Map;
public class HyperSqlMap {
public Map<String,Object> hyperSqlMap = new HashMap<String,Object>();
//岗位编码
public static String position_code="";
//品牌id
public static String empl_code="";
public HyperSqlMap(){
//key为hyper文件得名字,value为hyper文件得查询sql
hyperSqlMap.put("BI_HOS_SALES_CORR_V_B (BYIT)", "SELECT a1.* from BYIT.bi_hos_sales_curr_v a1 inner join "
+"(select distinct subordinate_position_code "
+ "from BYIT.auth_hos_sales_curr "
+" where position_code like '%"+position_code+"%' )a2 "
+"on a1.销售代表岗位代码 = a2.subordinate_position_code inner join "
+"(select distinct brand_name from BYIT.auth_empl_brand "
+"where empl_code like '%"+empl_code+"%' ) a3 "
+"on a1.品牌名称=a3.brand_name");
hyperSqlMap.put("BI_HOS_SALES_HIS_V_B (BYIT)", "SELECT a1.* "
+"from BYIT.bi_hos_sales_curr_v a1 inner join ("
+"select distinct subordinate_position_code "
+"from BYIT.auth_hos_sales_curr "
+"where position_code like '%"+position_code+"%' )a2 "
+"on a1.销售代表岗位代码=a2.subordinate_position_code "
+"inner join(select distinct brand_name from BYIT.auth_empl_brand "
+"where empl_code like '%"+empl_code+"%' )a3 "
+"on a1.品牌名称=a3.brand_name");
}
}
package com.byit.utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
/**
* @Description 属性文件工具类
* @author wych
* @date 2016年3月27日
* @version 1.0.0
*/
public class PropertiesUtil {
public static String getValue(String path, String key) throws IOException{
Properties properties = PropertiesUtil.getProperties(path);
return properties.getProperty(key);
}
private static Properties getProperties(String path) throws IOException{
Properties properties = new Properties();
InputStream inputStream = null;
if(StringUtils.isBlank(path)){
inputStream = PropertiesUtil.class.getResourceAsStream("/byit.properties");
}else{
inputStream = PropertiesUtil.class.getResourceAsStream(path);
}
properties.load(inputStream);
inputStream.close();
return properties;
}
}
#####localPath####
local.path = D:
spring.datasource.url=jdbc:oracle:thin:@10.0.120.166:1521:BYIT
spring.datasource.username=BYIT
spring.datasource.password=byit
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
\ No newline at end of file
package com.byit.job;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class MdJobApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment