Commit b585659a authored by litengwei's avatar litengwei

配置文件提交

parent 9b739c41
...@@ -162,11 +162,11 @@ ...@@ -162,11 +162,11 @@
<artifactId>vastbase-jdbc</artifactId> <artifactId>vastbase-jdbc</artifactId>
<version>2.7v</version> <version>2.7v</version>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>org.apache.shardingsphere</groupId> <!-- <groupId>org.apache.shardingsphere</groupId>-->
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <!-- <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>-->
<version>5.2.1</version> <!-- <version>5.2.1</version>-->
</dependency> <!-- </dependency>-->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>org.apache.shardingsphere</groupId>--> <!-- <groupId>org.apache.shardingsphere</groupId>-->
<!-- <artifactId>shardingsphere-transaction-xa-core</artifactId>--> <!-- <artifactId>shardingsphere-transaction-xa-core</artifactId>-->
......
...@@ -48,9 +48,9 @@ import com.yeejoin.amos.patrol.quartz.IJobService; ...@@ -48,9 +48,9 @@ import com.yeejoin.amos.patrol.quartz.IJobService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
import org.apache.commons.compress.utils.Sets; import org.apache.commons.compress.utils.Sets;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; //import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; //import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType; //import org.apache.shardingsphere.transaction.core.TransactionType;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
...@@ -109,7 +109,7 @@ import static com.alibaba.fastjson.JSON.toJSONString; ...@@ -109,7 +109,7 @@ import static com.alibaba.fastjson.JSON.toJSONString;
public class PlanTaskServiceImpl implements IPlanTaskService { public class PlanTaskServiceImpl implements IPlanTaskService {
private final Logger log = LoggerFactory.getLogger(PlanTaskServiceImpl.class); private final Logger log = LoggerFactory.getLogger(PlanTaskServiceImpl.class);
@Resource @Resource
private ShardingSphereDataSource dataSource; private DataSource dataSource;
@Autowired @Autowired
ESPlanTaskList esPlanTaskList; ESPlanTaskList esPlanTaskList;
......
package com.yeejoin.amos.patrol.config; //package com.yeejoin.amos.patrol.config;
//
//
import lombok.Getter; //import lombok.Getter;
import lombok.Setter; //import lombok.Setter;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; //import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
//
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.util.Assert; //import org.springframework.util.Assert;
//
import javax.annotation.PostConstruct; //import javax.annotation.PostConstruct;
import javax.annotation.Resource; //import javax.annotation.Resource;
import javax.sql.DataSource; //import javax.sql.DataSource;
import java.sql.Connection; //import java.sql.Connection;
import java.sql.ResultSet; //import java.sql.ResultSet;
import java.sql.SQLException; //import java.sql.SQLException;
import java.sql.Statement; //import java.sql.Statement;
import java.util.HashMap; //import java.util.HashMap;
import java.util.Map; //import java.util.Map;
//
/** ///**
* @author liran // * @author liran
*/ // */
@Slf4j //@Slf4j
@Setter //@Setter
@Getter //@Getter
@Component //@Component
public class TableCreate { //public class TableCreate {
//
@Resource // @Resource
private ShardingSphereDataSource dataSource; // private ShardingSphereDataSource dataSource;
//
Map<String, Object> createdTables = new HashMap<>(); // Map<String, Object> createdTables = new HashMap<>();
@Value("${shardingsphere.create.tables.num:10}") // @Value("${shardingsphere.create.tables.num:10}")
private String num; // private String num;
//
private String PLAN_TASK = "p_plan_task"; // private String PLAN_TASK = "p_plan_task";
private String PLAN_TASK_HISTORY = "p_plan_task_history_"; // private String PLAN_TASK_HISTORY = "p_plan_task_history_";
//
private String PLAN_TASK_DETAIL = "p_plan_task_detail"; // private String PLAN_TASK_DETAIL = "p_plan_task_detail";
private String PLAN_TASK_DETAIL_HISTORY = "p_plan_task_detail_history_"; // private String PLAN_TASK_DETAIL_HISTORY = "p_plan_task_detail_history_";
//
private String P_CHECK = "p_check"; // private String P_CHECK = "p_check";
private String P_CHECK_HISTORY = "p_check_history_"; // private String P_CHECK_HISTORY = "p_check_history_";
//
private String P_CHECK_INPUT = "p_check_input"; // private String P_CHECK_INPUT = "p_check_input";
private String P_CHECK_INPUT_HISTORY = "p_check_input_history_"; // private String P_CHECK_INPUT_HISTORY = "p_check_input_history_";
//
private String P_CHECK_SHOT = "p_check_shot"; // private String P_CHECK_SHOT = "p_check_shot";
private String P_CHECK_SHOT_HISTORY = "p_check_shot_history_"; // private String P_CHECK_SHOT_HISTORY = "p_check_shot_history_";
//
private String DB = "amos_tzs_biz."; // private String DB = "amos_tzs_biz.";
//
//
@PostConstruct // @PostConstruct
public void init() { // public void init() {
for(int i = 1; i<=Integer.parseInt(num); i++) { // for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(PLAN_TASK,DB,PLAN_TASK_HISTORY+i); // createNeedTime(PLAN_TASK,DB,PLAN_TASK_HISTORY+i);
} // }
for(int i = 1; i<=Integer.parseInt(num); i++) { // for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(PLAN_TASK_DETAIL,DB,PLAN_TASK_DETAIL_HISTORY+i); // createNeedTime(PLAN_TASK_DETAIL,DB,PLAN_TASK_DETAIL_HISTORY+i);
} // }
for(int i = 1; i<=Integer.parseInt(num); i++) { // for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK,DB,P_CHECK_HISTORY+i); // createNeedTime(P_CHECK,DB,P_CHECK_HISTORY+i);
} // }
for(int i = 1; i<=Integer.parseInt(num); i++) { // for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK_INPUT,DB,P_CHECK_INPUT_HISTORY+i); // createNeedTime(P_CHECK_INPUT,DB,P_CHECK_INPUT_HISTORY+i);
} // }
for(int i = 1; i<=Integer.parseInt(num); i++) { // for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK_SHOT,DB,P_CHECK_SHOT_HISTORY+i); // createNeedTime(P_CHECK_SHOT,DB,P_CHECK_SHOT_HISTORY+i);
} // }
} // }
//
//
private void createNeedTime(String table, String db, String create) { // private void createNeedTime(String table, String db, String create) {
DataSource dataSource = this.dataSource; // DataSource dataSource = this.dataSource;
String sql = "SHOW CREATE TABLE " + table; // String sql = "SHOW CREATE TABLE " + table;
String existSql = "select * from information_schema.tables where table_name ='" + table + "'; "; // String existSql = "select * from information_schema.tables where table_name ='" + table + "'; ";
doCreate(dataSource, sql, existSql, create, db, table); // doCreate(dataSource, sql, existSql, create, db, table);
} // }
//
private void doCreate(DataSource dataSource, String sql, String existSql, String create, String db, String table) { // private void doCreate(DataSource dataSource, String sql, String existSql, String create, String db, String table) {
String msg = " create table: " + create + " origin table: " + table + " db: " + db; // String msg = " create table: " + create + " origin table: " + table + " db: " + db;
Connection conn = null; // Connection conn = null;
Statement stmt = null; // Statement stmt = null;
try { // try {
conn = dataSource.getConnection().getMetaData().getConnection(); // conn = dataSource.getConnection().getMetaData().getConnection();
stmt = conn.createStatement(); // stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery(existSql); // ResultSet resultSet = stmt.executeQuery(existSql);
Assert.isTrue(resultSet.next(), msg + "初始化表不存在"); // Assert.isTrue(resultSet.next(), msg + "初始化表不存在");
//
ResultSet resTable = stmt.executeQuery(sql); // ResultSet resTable = stmt.executeQuery(sql);
Assert.isTrue(resTable.next(), msg + "初始化表不存在"); // Assert.isTrue(resTable.next(), msg + "初始化表不存在");
String existTableName = resTable.getString(1); // String existTableName = resTable.getString(1);
String createSqlOrigin = resTable.getString(2); // String createSqlOrigin = resTable.getString(2);
// log.info(existTableName, createSqlOrigin); // // log.info(existTableName, createSqlOrigin);
//
String existSqlNew = StringUtils.replaceOnce(existSql, existTableName, create); // String existSqlNew = StringUtils.replaceOnce(existSql, existTableName, create);
ResultSet executeQuery = stmt.executeQuery(existSqlNew); // ResultSet executeQuery = stmt.executeQuery(existSqlNew);
if (executeQuery.next()) { // if (executeQuery.next()) {
log.info("table exist :" + msg); // log.info("table exist :" + msg);
} else { // } else {
createSqlOrigin = createSqlOrigin.substring(0,createSqlOrigin.indexOf(";")); // createSqlOrigin = createSqlOrigin.substring(0,createSqlOrigin.indexOf(";"));
String creatsql = StringUtils.replace(createSqlOrigin, existTableName, create).replaceFirst(create, DB+create).replace("bigint(64)", "int8").replace("smallint(16)","int2"); // String creatsql = StringUtils.replace(createSqlOrigin, existTableName, create).replaceFirst(create, DB+create).replace("bigint(64)", "int8").replace("smallint(16)","int2");
if (0 == stmt.executeUpdate(creatsql)) { // if (0 == stmt.executeUpdate(creatsql)) {
log.info(msg + "success !"); // log.info(msg + "success !");
//
} else { // } else {
log.error(msg + "fail !"); // log.error(msg + "fail !");
} // }
} // }
} catch (Exception e) { // } catch (Exception e) {
log.error("create table fail error : {} ", e.getMessage()); // log.error("create table fail error : {} ", e.getMessage());
} finally { // } finally {
if (stmt != null) { // if (stmt != null) {
try { // try {
stmt.close(); // stmt.close();
} catch (SQLException e) { // } catch (SQLException e) {
log.error("SQLException", e); // log.error("SQLException", e);
} // }
} // }
if (conn != null) { // if (conn != null) {
try { // try {
conn.close(); // conn.close();
} catch (SQLException e) { // } catch (SQLException e) {
log.error("SQLException", e); // log.error("SQLException", e);
} // }
} // }
} // }
} // }
//
} //}
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