Skip to content

Commit

Permalink
v5.3.2 优化调度器,优化启动脚本,强制启动环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyachao committed Mar 30, 2024
1 parent bdfeceb commit 28b8471
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@
+ v5.3.1 [zdh_web]重构zdh_queue(为后期实时经营做基础)

+ v5.3.2 [zdh_web]所有模块优化代码
+ v5.3.2 [zdh_web]新增ZDH_RUN_MODE环境变量


+ v5.1.1 [zdh_web]支持hadoop,hive,hbase大数据权限(用户认证,数据权限)【未完成】
Expand Down
6 changes: 5 additions & 1 deletion release/bin/start.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@echo off
chcp 65001
set bin_path = %~dp0
cd %bin_path%../

java -Dfile.encoding=utf-8 -Dloader.path=libs/,conf/ -Xss512M -jar zdh_web.jar
set RUN_MODE=prod
set ZDH_RUN_MODE=%RUN_MODE%
java -Dspring.profiles.active=%RUN_MODE% -Dfile.encoding=utf-8 -Dloader.path=libs/,conf/ -Xss512M -jar zdh_web.jar
1 change: 1 addition & 0 deletions release/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cd "$bin_path/.."
pt=`pwd`
APP_NAME=${pt}"/zdh_web.jar"
RUN_MODE=prod
export ZDH_RUN_MODE=$RUN_MODE
nohup java -Dspring.profiles.active=$RUN_MODE -Dfile.encoding=utf-8 -Dloader.path=libs/,conf/ -Xms512M -jar "$APP_NAME" >> web.log &
2 changes: 2 additions & 0 deletions release/bin/zdh_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pt=`pwd`
APP_NAME=${pt}"/zdh_web.jar"
RUN_MODE=prod

export ZDH_RUN_MODE=$RUN_MODE

#APP_DIR=./
APP_DIR=`pwd`
echo "当前路径"
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/zyc/zdh/ZdhApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.zyc.zdh.annotation.MyMark;
import com.zyc.zdh.controller.LoginController;
import com.zyc.zdh.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Compatibility;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
Expand Down Expand Up @@ -37,9 +38,17 @@ public class ZdhApplication {
public static String start_time = DateUtil.getCurrentTime();

public static void main(String[] args) throws SocketException {
//检查必须配置的环境变量
String run_mode = System.getenv("ZDH_RUN_MODE");
if(StringUtils.isEmpty(run_mode)){
System.err.println("启动项目前必须配置ZDH_RUN_MODE环境变量,变量值同spring.active.profile值保持一致, linux: export ZDH_RUN_MODE=prod, windows: set ZDH_RUN_MODE=prod");
System.exit(-1);
}

SpringApplication springApplication = new SpringApplication(ZdhApplication.class);
ApplicationContext context = springApplication.run(args);
LoginController.context = context;

Environment env = context.getEnvironment();
String envPort = env.getProperty("server.port");
String envContext = env.getProperty("server.context-path", "");
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/zyc/zdh/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -73,8 +72,6 @@ public class LoginController {
private JemailService jemailService;
@Autowired
private PermissionMapper permissionMapper;
@Autowired
private Environment ev;

/**
* 系统根页面
Expand Down Expand Up @@ -126,7 +123,8 @@ public ReturnInfo<Object> register2(User user) {
}

//增加特别信息校验
Pattern pattern = Pattern.compile("(;|\\*|expr \\s*|delete \\s*)", Pattern.CASE_INSENSITIVE);
String pattern_str = "(;|\\*|expr \\s*|delete \\s*)";
Pattern pattern = Pattern.compile(pattern_str, Pattern.CASE_INSENSITIVE);
if (pattern.matcher(user.getUserName()).find() || pattern.matcher(user.getPassword()).find()) {
//此处可做校验判断,是否加入ip黑名单
return ReturnInfo.build(RETURN_CODE.FAIL.getCode(), "账户包含不合法字符,请修改后提交", null);
Expand Down
48 changes: 17 additions & 31 deletions src/main/java/com/zyc/zdh/quartz/ZdhInstanceIdGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,24 @@ public String generateInstanceId() throws SchedulerException {
try {
String myid=null;
String instancename=null;
// SystemCommandLineRunner systemCommandLineRunner = (SystemCommandLineRunner) SpringContext.getBean("systemCommandLineRunner");
Resource resource = new ClassPathResource("application.properties");
InputStream is = resource.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String data = null;
while((data = br.readLine()) != null) {
if(data.startsWith("spring.profiles.active")){
Resource app = new ClassPathResource("application-"+data.split("=")[1]+".properties");
InputStream is2 = app.getInputStream();
InputStreamReader isr2 = new InputStreamReader(is2);
BufferedReader br2 = new BufferedReader(isr2);
String data2 = null;
while((data2 = br2.readLine()) != null) {
if(data2.startsWith("myid")){
myid= data2.split("=")[1].trim();
}
if(data2.startsWith("zdh.schedule.quartz.scheduler.instanceName")){
instancename= data2.split("=")[1].trim();
}
}
br2.close();
isr2.close();
is2.close();
break;
}
}
br.close();
isr.close();
is.close();

String run_mode = System.getenv("ZDH_RUN_MODE");

Resource app = new ClassPathResource("application-"+run_mode+".properties");
InputStream is2 = app.getInputStream();
InputStreamReader isr2 = new InputStreamReader(is2);
BufferedReader br2 = new BufferedReader(isr2);
String data2 = null;
while((data2 = br2.readLine()) != null) {
if(data2.startsWith("myid")){
myid= data2.split("=")[1].trim();
}
if(data2.startsWith("zdh.schedule.quartz.scheduler.instanceName")){
instancename= data2.split("=")[1].trim();
}
}
br2.close();
isr2.close();
is2.close();
return instancename+"_"+myid;

} catch (IOException e) {
Expand Down

0 comments on commit 28b8471

Please sign in to comment.