|
@@ -7,6 +7,8 @@ import org.bfkj.utils.LogUtils;
|
|
|
import org.bfkj.utils.MapTools;
|
|
|
import org.bfkj.utils.MyDbHelper;
|
|
|
import org.bfkj.utils.ScheduleUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.SpringApplication;
|
|
@@ -20,7 +22,6 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import java.io.File;
|
|
|
import java.util.*;
|
|
|
import java.util.logging.Level;
|
|
|
-import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
|
* 初始化
|
|
@@ -30,7 +31,7 @@ import java.util.logging.Logger;
|
|
|
@EnableScheduling
|
|
|
public class MainFactoryApplication implements InitializingBean {
|
|
|
|
|
|
- private static final Logger logger = Logger.getLogger(MainFactoryApplication.class.getName());
|
|
|
+ private final static Logger logger = LoggerFactory.getLogger(MainFactoryApplication.class);
|
|
|
|
|
|
private static final String INSERT_SQL = "INSERT INTO log_success ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
private static final String ERROR_SQL = "INSERT INTO log_error ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
|
@@ -50,7 +51,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
public static void main(String[] args) {
|
|
|
String path = System.getProperty("user.dir"); //获取当前项目的路径
|
|
|
if (!checkFileDir(path)) {
|
|
|
- logger.log(Level.SEVERE, "配置文件夹检测失败");
|
|
|
+ logger.error("配置文件夹检测失败");
|
|
|
return;
|
|
|
}
|
|
|
/*获取初始地址*/
|
|
@@ -70,18 +71,18 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
}
|
|
|
MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
|
|
|
if (Objects.nonNull(myDbHelper.getErrorMessage())) {
|
|
|
- logger.log(Level.SEVERE, "初始化获取MyDbHelper对象异常");
|
|
|
+ logger.error("初始化获取MyDbHelper对象异常");
|
|
|
return;
|
|
|
}
|
|
|
if (!initDB(myDbHelper)) {
|
|
|
- logger.log(Level.SEVERE, "初始化远程数据库失败");
|
|
|
+ logger.error("初始化远程数据库失败");
|
|
|
return;
|
|
|
}
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(MainFactoryApplication::currentWorkExit));
|
|
|
try {
|
|
|
Map<String, String> hasDeployNodeIDMap = myDbHelper.queryForObject("select Max(deployNodeID) from deploynode where serviceURL = ? ", AppConfig.serviceURL);
|
|
|
if ("-1".equals(hasDeployNodeIDMap.get("code"))) {
|
|
|
- logger.log(Level.SEVERE, "初始化获取机器表信息: 执行SQL失败 %s".formatted(hasDeployNodeIDMap.get("message")));
|
|
|
+ logger.error("初始化获取机器表信息: 执行SQL失败 {}",hasDeployNodeIDMap.get("message"));
|
|
|
return;
|
|
|
}
|
|
|
String workID = hasDeployNodeIDMap.get("returnData");
|
|
@@ -90,24 +91,24 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
} else {
|
|
|
Map<String, String> returnKeyValues = myDbHelper.insertReturnKeyValues("insert into deploynode(serviceURL) values(?)", AppConfig.serviceURL);
|
|
|
if ("-1".equals(returnKeyValues.get("code"))) {
|
|
|
- logger.log(Level.SEVERE, "根据serviceURL新增入库失败: " + ("insert into deploynode(serviceURL) values(?)") + " 参数: " + AppConfig.serviceURL);
|
|
|
+ logger.error("根据serviceURL新增入库失败: {}{}{}" , "insert into deploynode(serviceURL) values(?)" , " 参数: " , AppConfig.serviceURL);
|
|
|
return;
|
|
|
}
|
|
|
AppConfig.WORK_ID = returnKeyValues.get("returnData");
|
|
|
if (!MapTools.isNumber(AppConfig.WORK_ID)) {
|
|
|
- logger.log(Level.SEVERE, "初始化workID异常: " + AppConfig.WORK_ID);
|
|
|
+ logger.error("初始化workID异常: {}" , AppConfig.WORK_ID);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.log(Level.SEVERE, "初始化workID异常: " + LogUtils.getException(e));
|
|
|
+ logger.error("初始化workID异常: {}" , LogUtils.getException(e));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Map<String, Object> serviceListResult = myDbHelper.queryByParamsReturnList("SELECT serviceID,serviceType FROM serviceinfo WHERE workId = ?", AppConfig.WORK_ID);
|
|
|
List<Map<String, Object>> serviceList = MapTools.getMapList(serviceListResult);
|
|
|
if (!"0".equals(serviceListResult.get("code")) || null == serviceList) {
|
|
|
- logger.log(Level.SEVERE, "初始化获取服务异常: " + serviceListResult.get("message"));
|
|
|
+ logger.error("初始化获取服务异常: " + serviceListResult.get("message"));
|
|
|
return;
|
|
|
}
|
|
|
int autoCount = 0;
|
|
@@ -121,7 +122,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
ServiceInputControl.startOrStop(requestParams, "1");
|
|
|
}
|
|
|
}
|
|
|
- logger.log(Level.INFO, "本机共部署服务个数:" + serviceList.size() + ",启动主动采集个数:" + autoCount);
|
|
|
+ logger.info("本机共部署服务个数:{},启动主动采集个数:{}", serviceList.size(), autoCount);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -146,7 +147,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
//关闭数据库连接
|
|
|
ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT).close();
|
|
|
ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_LOG_CONNECT).close();
|
|
|
- logger.log(Level.INFO, "系统正常退出");
|
|
|
+ logger.info("系统正常退出");
|
|
|
}
|
|
|
|
|
|
/*创建文件夹*/
|
|
@@ -174,7 +175,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
|
|
|
Map<String, String> hasAppMap = myDbHelper.queryForObject("select count(1) hasCount from t_application where app_id =?", "1");
|
|
|
if ("-1".equals(hasAppMap.get("code"))) {
|
|
|
- System.out.println("初始化数据库 查询应用信息,查询失败: " + hasAppMap.get("message"));
|
|
|
+ logger.error("初始化数据库 查询应用信息,查询失败:{} ", hasAppMap.get("message"));
|
|
|
return false;
|
|
|
}
|
|
|
String hasApp = hasAppMap.get("returnData");
|
|
@@ -185,7 +186,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
|
|
|
Map<String, String> hasUserApp = myDbHelper.queryForObject("select count(1) hasUser from t_user where user_id =?", "1");
|
|
|
if ("-1".equals(hasUserApp.get("code"))) {
|
|
|
- System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
|
|
|
+ logger.error("初始化数据库 查询用户信息信息,查询失败: {}", hasAppMap.get("message"));
|
|
|
return false;
|
|
|
}
|
|
|
String hasUser = hasUserApp.get("returnData");
|
|
@@ -196,7 +197,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
|
|
|
Map<String, String> hasAuthApp = myDbHelper.queryForObject("select count(1) hasAuth from t_auth");
|
|
|
if ("-1".equals(hasAuthApp.get("code"))) {
|
|
|
- System.out.println("初始化数据库 查询权限信息信息,查询失败: " + hasAppMap.get("message"));
|
|
|
+ logger.error("初始化数据库 查询权限信息信息,查询失败: {}", hasAppMap.get("message"));
|
|
|
return false;
|
|
|
}
|
|
|
String hasAuth = hasAuthApp.get("returnData");
|
|
@@ -207,7 +208,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
|
|
|
Map<String, String> hasServiceApp = myDbHelper.queryForObject("select count(1) hasService from serviceinfo");
|
|
|
if ("-1".equals(hasServiceApp.get("code"))) {
|
|
|
- System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
|
|
|
+ logger.error("初始化数据库 查询用户信息信息,查询失败: {}", hasAppMap.get("message"));
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -270,7 +271,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
}
|
|
|
MyDbHelper logDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_LOG_CONNECT);
|
|
|
if (Objects.nonNull(logDbHelper.getErrorMessage())) {
|
|
|
- System.out.println("获取日志数据库失败");
|
|
|
+ logger.error("获取日志数据库失败");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -278,7 +279,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
logDbHelper.JDBCBatch(INSERT_SQL, logSuccessList, null);
|
|
|
logDbHelper.JDBCBatch(ERROR_SQL, logErrorList, null);
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println("日志记录异常" + LogUtils.getException(e));
|
|
|
+ logger.warn("日志记录异常 {}", LogUtils.getException(e));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -297,7 +298,7 @@ public class MainFactoryApplication implements InitializingBean {
|
|
|
AppConfig.SOURCE_DATA = enableSourceData;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println("配置文件中,连接数据库信息错误");
|
|
|
+ logger.error("配置文件中,连接数据库信息错误: {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|