Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e9de7ee64 | ||
|
|
e352927396 | ||
|
|
51b26c077d | ||
|
|
2c5f55a876 | ||
|
|
c52f7f5c77 | ||
|
|
7f46d2d371 | ||
|
|
34d8201641 | ||
|
|
92e1c1d9ef | ||
|
|
ee3748c361 | ||
|
|
439947caad | ||
|
|
17706e8065 | ||
|
|
8853e3170d | ||
|
|
222f37afc1 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,4 +4,4 @@ rebel.xml
|
||||
/.idea/
|
||||
*.iml
|
||||
/static/
|
||||
/ipdb/
|
||||
/config/
|
||||
|
||||
32
pom.xml
32
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>springboot-parent</name>
|
||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||
@@ -58,55 +58,55 @@
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-db-migration</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-web</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-message</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -124,13 +124,23 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>kepai-repo-plugin</id>
|
||||
<url>http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>launcher-maven-plugin</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-ademo</artifactId>
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
|
||||
GlobalConfig globalConfig;
|
||||
|
||||
@Override
|
||||
public CurrentWebUser getCurrentUserName(String userId) {
|
||||
public CurrentWebUser getCurrentUserName(TokenBean tokenBean) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.tiesheng.demo.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.tiesheng.annotation.token.TokenIgnore;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.message.config.aliyun.AliyunSmsConfig;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
@@ -24,17 +27,24 @@ public class TestController {
|
||||
GlobalConfig globalConfig;
|
||||
@Autowired
|
||||
AliyunSmsConfig aliyunSmsConfig;
|
||||
@Autowired
|
||||
TsTokenConfig tsTokenConfig;
|
||||
|
||||
@RequestMapping("/index")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> index() {
|
||||
|
||||
TokenBean tokenBean = new TokenBean("11", "", "fdfd");
|
||||
LogFactory.get().info(tokenBean.toToken());
|
||||
|
||||
return ApiResp.respOK("hello world");
|
||||
}
|
||||
|
||||
@RequestMapping("/redirect")
|
||||
@TokenIgnore
|
||||
public void redirect(HttpServletResponse response) {
|
||||
globalConfig.redirect("mobile", "/test", response);
|
||||
tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
|
||||
// globalConfig.redirect("mobile", "/test", response);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +76,7 @@ public class TestController {
|
||||
@RequestMapping("/uploadPath")
|
||||
@TokenIgnore
|
||||
public ApiResp<String> uploadPath() {
|
||||
FileUploadPath uploadPath = FileUploadPath.get("http://scv6.tmp.kepai365.ltd/upload/2023-01/2b4b6b7b-70d0-4683-859a-f799adc4f04c.xls");
|
||||
FileUploadPath uploadPath = FileUploadPath.file("http://scv6.tmp.kepai365.ltd/upload/2023-01/2b4b6b7b-70d0-4683-859a-f799adc4f04c.xls");
|
||||
return ApiResp.respOK(uploadPath.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
28
springboot-ademo/src/main/resources/application-test.yml
Normal file
28
springboot-ademo/src/main/resources/application-test.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
## Spring配置
|
||||
spring:
|
||||
|
||||
## 数据库配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://47.96.30.85:3306/com_tiesheng_web?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&queryTimeout=5400&allowMultiQueries=true&serverTimezone=GMT%2B8
|
||||
username: com_tiesheng_web
|
||||
password: 4Xo$XheGFc
|
||||
|
||||
platform:
|
||||
wxmp:
|
||||
global:
|
||||
app-id: wxa0343fe519824651
|
||||
app-secret: 776f089ba70bcd66455a7c7893f810b9
|
||||
|
||||
tiesheng:
|
||||
token:
|
||||
ignores:
|
||||
"1111":
|
||||
id: "1111"
|
||||
global:
|
||||
version: 2
|
||||
host: http://localhost:8080
|
||||
aliyun:
|
||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||
sign-name: 阿里云短信测试
|
||||
@@ -1,28 +1,21 @@
|
||||
server:
|
||||
compression:
|
||||
enabled: true
|
||||
|
||||
## Spring配置
|
||||
spring:
|
||||
|
||||
## 数据库配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://47.96.30.85:3306/com_tiesheng_web?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&queryTimeout=5400&allowMultiQueries=true&serverTimezone=GMT%2B8
|
||||
username: com_tiesheng_web
|
||||
password: 4Xo$XheGFc
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
web:
|
||||
resources:
|
||||
static-locations: classpath:/static/,file:static/
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
||||
platform:
|
||||
wxmp:
|
||||
global:
|
||||
app-id: wxa0343fe519824651
|
||||
app-secret: 776f089ba70bcd66455a7c7893f810b9
|
||||
|
||||
tiesheng:
|
||||
token:
|
||||
ignores:
|
||||
"1111":
|
||||
id: "1111"
|
||||
global:
|
||||
version: 2
|
||||
host: http://localhost:8080
|
||||
aliyun:
|
||||
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
|
||||
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
|
||||
sign-name: 阿里云短信测试
|
||||
## 日志
|
||||
logging:
|
||||
file:
|
||||
name: logs/tiesheng.log
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-db-migration</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>launcher-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
||||
@@ -28,6 +28,7 @@ public class CopyLauncherScriptMojo extends AbstractMojo {
|
||||
public void execute() throws MojoExecutionException {
|
||||
try {
|
||||
copy("launchScript");
|
||||
System.out.println("initScript success.");
|
||||
} catch (IOException e) {
|
||||
throw new MojoExecutionException("copy launchScript error!");
|
||||
}
|
||||
|
||||
@@ -40,82 +40,11 @@ done
|
||||
jarfolder="$( (cd "$(dirname "$jarfile")" && pwd -P) )"
|
||||
cd "$WORKING_DIR" || exit 1
|
||||
|
||||
# Source any config file
|
||||
configfile="$(basename "${jarfile%.*}.conf")"
|
||||
|
||||
# Initialize CONF_FOLDER location defaulting to jarfolder
|
||||
[[ -z "$CONF_FOLDER" ]] && CONF_FOLDER="{{confFolder:${jarfolder}}}"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}"
|
||||
|
||||
# Initialize PID/LOG locations if they weren't provided by the config file
|
||||
[[ -z "$PID_FOLDER" ]] && PID_FOLDER="{{pidFolder:/var/run}}"
|
||||
[[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="{{logFolder:/var/log}}"
|
||||
! [[ "$PID_FOLDER" == /* ]] && PID_FOLDER="$(dirname "$jarfile")"/"$PID_FOLDER"
|
||||
! [[ "$LOG_FOLDER" == /* ]] && LOG_FOLDER="$(dirname "$jarfile")"/"$LOG_FOLDER"
|
||||
! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp"
|
||||
! [[ -x "$LOG_FOLDER" ]] && LOG_FOLDER="/tmp"
|
||||
|
||||
# Set up defaults
|
||||
[[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run"
|
||||
[[ -z "$USE_START_STOP_DAEMON" ]] && USE_START_STOP_DAEMON="{{useStartStopDaemon:true}}"
|
||||
|
||||
# Create an identity for log/pid files
|
||||
if [[ -z "$identity" ]]; then
|
||||
if [[ -n "$init_script" ]]; then
|
||||
identity="${init_script}"
|
||||
else
|
||||
identity=$(basename "${jarfile%.*}")_${jarfolder//\//}
|
||||
fi
|
||||
fi
|
||||
|
||||
# Initialize log file name if not provided by the config file
|
||||
[[ -z "$LOG_FILENAME" ]] && LOG_FILENAME="{{logFilename:${identity}.log}}"
|
||||
|
||||
# Initialize stop wait time if not provided by the config file
|
||||
[[ -z "$STOP_WAIT_TIME" ]] && STOP_WAIT_TIME="{{stopWaitTime:60}}"
|
||||
|
||||
# ANSI Colors
|
||||
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
|
||||
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
|
||||
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
|
||||
|
||||
# Utility functions
|
||||
checkPermissions() {
|
||||
touch "$pid_file" &> /dev/null || { echoRed "Operation not permitted (cannot access pid file)"; return 4; }
|
||||
touch "$log_file" &> /dev/null || { echoRed "Operation not permitted (cannot access log file)"; return 4; }
|
||||
}
|
||||
|
||||
isRunning() {
|
||||
ps -p "$1" | grep -v "PID" &> /dev/null
|
||||
}
|
||||
|
||||
await_file() {
|
||||
end=$(date +%s)
|
||||
let "end+=10"
|
||||
while [[ ! -s "$1" ]]
|
||||
do
|
||||
now=$(date +%s)
|
||||
if [[ $now -ge $end ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
# Determine the script mode
|
||||
action="config"
|
||||
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
|
||||
action="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
# Build the pid and log filenames
|
||||
PID_FOLDER="$PID_FOLDER/${identity}"
|
||||
pid_file="$PID_FOLDER/{{pidFilename:${identity}.pid}}"
|
||||
log_file="$LOG_FOLDER/$LOG_FILENAME"
|
||||
|
||||
# Determine the user to run as if we are root
|
||||
# shellcheck disable=SC2012
|
||||
[[ $(id -u) == "0" ]] && run_user=$(ls -ld "$jarfile" | awk '{print $3}')
|
||||
@@ -132,125 +61,39 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
arguments=(-Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS -jar "$jarfile" $RUN_ARGS "$@")
|
||||
|
||||
# Action functions
|
||||
start() {
|
||||
if [[ -f "$pid_file" ]]; then
|
||||
pid=$(cat "$pid_file")
|
||||
isRunning "$pid" && { echoYellow "Already running [$pid]"; return 0; }
|
||||
fi
|
||||
do_start "$@"
|
||||
}
|
||||
## 配置service
|
||||
service() {
|
||||
|
||||
do_start() {
|
||||
tempCahr='$'
|
||||
|
||||
## 创建service文件
|
||||
working_dir=$(dirname "$jarfile")
|
||||
pushd "$working_dir" > /dev/null
|
||||
mkdir -p "$PID_FOLDER" &> /dev/null
|
||||
if [[ -n "$run_user" ]]; then
|
||||
checkPermissions || return $?
|
||||
chown "$run_user" "$PID_FOLDER"
|
||||
chown "$run_user" "$pid_file"
|
||||
chown "$run_user" "$log_file"
|
||||
if [ $USE_START_STOP_DAEMON = true ] && type start-stop-daemon > /dev/null 2>&1; then
|
||||
start-stop-daemon --start --quiet \
|
||||
--chuid "$run_user" \
|
||||
--name "$identity" \
|
||||
--make-pidfile --pidfile "$pid_file" \
|
||||
--background --no-close \
|
||||
--startas "$javaexe" \
|
||||
--chdir "$working_dir" \
|
||||
-- "${arguments[@]}" \
|
||||
>> "$log_file" 2>&1
|
||||
await_file "$pid_file"
|
||||
else
|
||||
su -s /bin/sh -c "$javaexe $(printf "\"%s\" " "${arguments[@]}") >> \"$log_file\" 2>&1 & echo \$!" "$run_user" > "$pid_file"
|
||||
fi
|
||||
pid=$(cat "$pid_file")
|
||||
else
|
||||
checkPermissions || return $?
|
||||
"$javaexe" "${arguments[@]}" >> "$log_file" 2>&1 &
|
||||
pid=$!
|
||||
disown $pid
|
||||
echo "$pid" > "$pid_file"
|
||||
fi
|
||||
[[ -z $pid ]] && { echoRed "Failed to start"; return 1; }
|
||||
echoGreen "Started [$pid]"
|
||||
service_file="/etc/systemd/system/$1.service"
|
||||
|
||||
echo "[Unit]" > $service_file
|
||||
echo "Description=$1" >> $service_file
|
||||
echo "After=rc-local.service network.target remote-fs.target nss-lookup.target" >> $service_file
|
||||
|
||||
echo "" >> $service_file
|
||||
echo "[Service]" >> $service_file
|
||||
echo "Type=forking" >> $service_file
|
||||
echo "WorkingDirectory=$working_dir" >> $service_file
|
||||
echo "ExecStart=/bin/sh -c '$javaexe -Xms64m -Xmx128m -Dserver.port=$2 -Dspring.profiles.active=$3 -jar $jarfile > /dev/null 2>&1 &'" >> $service_file
|
||||
echo "ExecReload=/bin/kill -s HUP ${tempCahr}MAINPID" >> $service_file
|
||||
echo "ExecStop=/bin/kill -s QUIT ${tempCahr}MAINPID" >> $service_file
|
||||
|
||||
echo "" >> $service_file
|
||||
echo "[Install]" >> $service_file
|
||||
echo "WantedBy=multi-user.target" >> $service_file
|
||||
systemctl daemon-reload
|
||||
|
||||
## 自启动
|
||||
systemctl enable $1
|
||||
|
||||
## 配置成功
|
||||
echoGreen "config success, use 'systemctl start $1 ' to start"
|
||||
|
||||
}
|
||||
|
||||
stop() {
|
||||
working_dir=$(dirname "$jarfile")
|
||||
pushd "$working_dir" > /dev/null
|
||||
[[ -f $pid_file ]] || { echoYellow "Not running (pidfile not found)"; return 0; }
|
||||
pid=$(cat "$pid_file")
|
||||
isRunning "$pid" || { echoYellow "Not running (process ${pid}). Removing stale pid file."; rm -f "$pid_file"; return 0; }
|
||||
do_stop "$pid" "$pid_file"
|
||||
}
|
||||
|
||||
do_stop() {
|
||||
kill "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; }
|
||||
for i in $(seq 1 $STOP_WAIT_TIME); do
|
||||
isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; }
|
||||
[[ $i -eq STOP_WAIT_TIME/2 ]] && kill "$1" &> /dev/null
|
||||
sleep 1
|
||||
done
|
||||
echoRed "Unable to kill process $1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop && start
|
||||
}
|
||||
|
||||
status() {
|
||||
working_dir=$(dirname "$jarfile")
|
||||
pushd "$working_dir" > /dev/null
|
||||
[[ -f "$pid_file" ]] || { echoRed "Not running"; return 3; }
|
||||
pid=$(cat "$pid_file")
|
||||
isRunning "$pid" || { echoRed "Not running (process ${pid} not found)"; return 1; }
|
||||
echoGreen "Running [$pid]"
|
||||
return 0
|
||||
}
|
||||
|
||||
run() {
|
||||
pushd "$(dirname "$jarfile")" > /dev/null
|
||||
"$javaexe" "${arguments[@]}"
|
||||
result=$?
|
||||
popd > /dev/null
|
||||
return "$result"
|
||||
}
|
||||
|
||||
config() {
|
||||
|
||||
## 设置自启动
|
||||
ln -s $jarfile /etc/init.d/$1
|
||||
chkconfig --add $1
|
||||
|
||||
## 生成配置文件
|
||||
working_dir=$(dirname "$jarfile")
|
||||
conf_file="$working_dir/$configfile"
|
||||
echo "LOG_FOLDER=/dev" > $conf_file
|
||||
echo "LOG_FILENAME=null" >> $conf_file
|
||||
echo "RUN_ARGS='--server.port=$2 --spring.profiles.active=$3'" >> $conf_file
|
||||
echo "JAVA_OPTS='-Dfile.encoding=utf-8'" >> $conf_file
|
||||
}
|
||||
|
||||
# Call the appropriate action function
|
||||
case "$action" in
|
||||
start)
|
||||
start "$@"; exit $?;;
|
||||
stop)
|
||||
stop "$@"; exit $?;;
|
||||
restart)
|
||||
restart "$@"; exit $?;;
|
||||
status)
|
||||
status "$@"; exit $?;;
|
||||
run)
|
||||
run "$@"; exit $?;;
|
||||
config)
|
||||
config "$1" "$2" "$3" ; exit $?;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status|run|config}"; exit 1;
|
||||
esac
|
||||
|
||||
service "$@"
|
||||
exit 0
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.tiesheng.login.config.token;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.jwt.JWT;
|
||||
import cn.hutool.jwt.JWTValidator;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
@@ -66,10 +68,21 @@ public class TsTokenConfig {
|
||||
/**
|
||||
* 验证token
|
||||
*
|
||||
* @param thrExp
|
||||
* @return
|
||||
*/
|
||||
public TokenBean validToken(boolean thrExp) {
|
||||
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
||||
return validToken(token, thrExp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenBean validToken(String token, boolean thrExp) {
|
||||
TokenBean tokenBean = isIgnored(token);
|
||||
if (tokenBean != null) {
|
||||
return tokenBean;
|
||||
@@ -77,15 +90,11 @@ public class TsTokenConfig {
|
||||
|
||||
try {
|
||||
JWT decode = JWT.of(token);
|
||||
JWTValidator.of(decode).validateDate();
|
||||
String id = decode.getPayload("id").toString();
|
||||
String environmentType = decode.getPayload("environmentType").toString();
|
||||
String service = decode.getPayload("service").toString();
|
||||
String extra = decode.getPayload("extra").toString();
|
||||
Long expireTime = decode.getPayloads().getLong("time");
|
||||
if (expireTime != null && expireTime < System.currentTimeMillis()) {
|
||||
throw new ApiException("登录过期,请重新登陆");
|
||||
}
|
||||
|
||||
tokenBean = new TokenBean(id, environmentType, service);
|
||||
tokenBean.setExtra(extra);
|
||||
} catch (Exception ignored) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tiesheng.login.config.token.bean;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.jwt.JWT;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
@@ -31,11 +32,11 @@ public class TokenBean {
|
||||
public String toToken() {
|
||||
TsTokenConfig tsTokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
||||
return JWT.create()
|
||||
.setExpiresAt(DateUtil.offsetHour(DateUtil.date(), tsTokenConfig.getExpireHours()))
|
||||
.setPayload("id", getId())
|
||||
.setPayload("environmentType", getEnvironmentType())
|
||||
.setPayload("service", getService())
|
||||
.setPayload("extra", getExtra())
|
||||
.setPayload("time", System.currentTimeMillis() + tsTokenConfig.getExpireHours() * 1000 * 60 * 60)
|
||||
.setKey(tsTokenConfig.getEncryptKey().getBytes())
|
||||
.sign();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-message</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-util</artifactId>
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.io.RandomAccessFile;
|
||||
public class Ip2regionConfig {
|
||||
|
||||
private String dbUrl = "http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master/ipdb/ip2region.db";
|
||||
private String dbPath = System.getProperty("user.dir") + "/ipdb/ip2region.db";
|
||||
private String dbPath = System.getProperty("user.dir") + "/config/ip2region.db";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 逻辑方法
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.tiesheng.util.pojos;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
@@ -29,19 +30,26 @@ public class FileUploadPath {
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static FileUploadPath get(String fileName) {
|
||||
public static FileUploadPath file(String fileName) {
|
||||
|
||||
// 下载文件
|
||||
fileName = downloadFile(fileName);
|
||||
fileName = fileDownload(fileName);
|
||||
|
||||
FileUploadPath pathBean = new FileUploadPath();
|
||||
|
||||
String tempPath = fileName;
|
||||
if (!StrUtil.startWith(tempPath, CharUtil.SLASH)) {
|
||||
tempPath = CharUtil.SLASH + tempPath;
|
||||
}
|
||||
if (!StrUtil.startWith(tempPath, UPLOAD_FOLDER)) {
|
||||
tempPath = UPLOAD_FOLDER + DateUtil.format(DateUtil.date(), "yyyy-MM") + "/" + fileName;
|
||||
tempPath = UPLOAD_FOLDER + DateUtil.format(DateUtil.date(), "yyyy-MM") + CharUtil.SLASH + fileName;
|
||||
}
|
||||
pathBean.setHttpPath(tempPath);
|
||||
pathBean.setAbsolutePath(String.format("%s/static%s", System.getProperty("user.dir"), tempPath));
|
||||
|
||||
String tempAbs = String.format("%s/static%s", System.getProperty("user.dir"), tempPath);
|
||||
tempAbs = FileUtil.normalize(tempAbs);
|
||||
pathBean.setAbsolutePath(tempAbs);
|
||||
|
||||
FileUtil.mkParentDirs(pathBean.getAbsolutePath());
|
||||
|
||||
return pathBean;
|
||||
@@ -51,40 +59,33 @@ public class FileUploadPath {
|
||||
/**
|
||||
* 下载http文件
|
||||
*
|
||||
* @param fileName
|
||||
* @param httpUrl
|
||||
* @return
|
||||
*/
|
||||
public static String downloadFile(String fileName) {
|
||||
if (!StrUtil.startWith(fileName, "http")) {
|
||||
return fileName;
|
||||
public static String fileDownload(String httpUrl) {
|
||||
if (!StrUtil.startWith(httpUrl, "http")) {
|
||||
return httpUrl;
|
||||
}
|
||||
String newFileName = UPLOAD_FOLDER + StrUtil.subAfter(fileName, UPLOAD_FOLDER, true);
|
||||
FileUploadPath uploadPath = get(newFileName);
|
||||
String newFileName = UPLOAD_FOLDER + StrUtil.subAfter(httpUrl, UPLOAD_FOLDER, true);
|
||||
FileUploadPath uploadPath = file(newFileName);
|
||||
if (!FileUtil.exist(uploadPath.getAbsolutePath())) {
|
||||
HttpUtil.downloadFile(fileName, uploadPath.getAbsolutePath());
|
||||
HttpUtil.downloadFile(httpUrl, uploadPath.getAbsolutePath());
|
||||
}
|
||||
|
||||
return uploadPath.getHttpPath();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 随机生成一个文件路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static FileUploadPath random() {
|
||||
return get(IdUtil.simpleUUID());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 随机生成一个文件路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static FileUploadPath random(String fileExt) {
|
||||
return get(IdUtil.simpleUUID() + "." + fileExt);
|
||||
String fileName = IdUtil.simpleUUID();
|
||||
if (!StrUtil.isEmpty(fileExt)) {
|
||||
fileName = fileName + "." + fileExt;
|
||||
}
|
||||
return file(fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,20 +96,9 @@ public class FileUploadPath {
|
||||
* @return
|
||||
*/
|
||||
public static FileUploadPath folder(String folder) {
|
||||
FileUploadPath pathBean = new FileUploadPath();
|
||||
|
||||
String tempFolder = folder;
|
||||
if (!StrUtil.startWith(tempFolder, UPLOAD_FOLDER)) {
|
||||
tempFolder = UPLOAD_FOLDER + tempFolder;
|
||||
}
|
||||
if (!StrUtil.endWith(folder, "/")) {
|
||||
tempFolder = tempFolder + "/";
|
||||
}
|
||||
pathBean.setHttpPath(tempFolder);
|
||||
pathBean.setAbsolutePath(String.format("%s/static%s", System.getProperty("user.dir"), tempFolder));
|
||||
FileUtil.mkParentDirs(pathBean.getAbsolutePath());
|
||||
|
||||
return pathBean;
|
||||
FileUploadPath file = file(folder);
|
||||
FileUtil.mkdir(file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-web</artifactId>
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.tiesheng.core.pojos.dao.CoreLogMessage;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.service.TieshengMessageConfigurer;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
@@ -53,7 +54,7 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
*/
|
||||
public void addOperationLog(String title, String subject, Object params) {
|
||||
CoreLogOperation operation = new CoreLogOperation();
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(TsTokenConfig.get().getId());
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(TsTokenConfig.get());
|
||||
operation.setUserId(currentWebUser.getId());
|
||||
operation.setUserName(currentWebUser.getName());
|
||||
operation.setTitle(title);
|
||||
@@ -72,8 +73,9 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
* 添加登录日志
|
||||
*
|
||||
* @param platformUnique
|
||||
* @param tokenBean
|
||||
*/
|
||||
public void addLoginLog(CorePlatformUnique platformUnique) {
|
||||
public void addLoginLog(CorePlatformUnique platformUnique, TokenBean tokenBean) {
|
||||
|
||||
HttpServletRequest request = ServletKit.getRequest();
|
||||
String ip = ServletUtil.getClientIP(request);
|
||||
@@ -82,7 +84,7 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
|
||||
login.setUserId(platformUnique.getUserId());
|
||||
login.setPlatform(platformUnique.getPlatform());
|
||||
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(platformUnique.getUserId());
|
||||
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(tokenBean);
|
||||
login.setUserName(currentWebUser.getName());
|
||||
|
||||
login.setIp(ip);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
||||
saveOrUpdate(platformUnique);
|
||||
|
||||
// 添加登录日志
|
||||
coreLogService.addLoginLog(platformUnique);
|
||||
coreLogService.addLoginLog(platformUnique,tokenBean);
|
||||
}
|
||||
return tokenBean;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface TieshengWebConfigurer {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
CurrentWebUser getCurrentUserName(String userId);
|
||||
CurrentWebUser getCurrentUserName(TokenBean userId);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
server:
|
||||
compression:
|
||||
enabled: true
|
||||
|
||||
## Spring配置
|
||||
spring:
|
||||
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
web:
|
||||
resources:
|
||||
static-locations: classpath:/static/,file:static/
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
||||
## 日志
|
||||
logging:
|
||||
file:
|
||||
name: logs/tiesheng.log
|
||||
Reference in New Issue
Block a user