Commit eb0fc377 authored by lisong's avatar lisong

数据归档添加删除逻辑

parent d9420f49
......@@ -291,6 +291,9 @@ public interface PlanTaskMapper extends BaseMapper {
List<Check> findCheck();
void truncateTable(@Param("tableName")String tableName);
List<CheckInput> findCheckInput();
List<CheckShot> findCheckShot();
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
import com.sun.corba.se.impl.activation.RepositoryImpl;
......@@ -38,6 +39,7 @@ import com.yeejoin.amos.patrol.business.util.Toke;
import com.yeejoin.amos.patrol.business.util.WordTemplateUtils;
import com.yeejoin.amos.patrol.business.vo.*;
import com.yeejoin.amos.patrol.common.enums.*;
import com.yeejoin.amos.patrol.config.DataSourceConfiguration;
import com.yeejoin.amos.patrol.core.common.request.CommonPageable;
import com.yeejoin.amos.patrol.core.common.response.AppCheckInputRespone;
import com.yeejoin.amos.patrol.core.common.response.AppPointCheckRespone;
......@@ -2441,6 +2443,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}).collect(Collectors.toList());
repositoryTs.batchSaveBySharding(collect);
planTaskMapper.truncateTable("p_plan_task");
log.info("归档p_plan_task表完成========");
}
......@@ -2454,6 +2457,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return d;
}).collect(Collectors.toList());
repositoryTs.batchSaveBySharding(collect);
planTaskMapper.truncateTable("p_plan_task_detail");
log.info("归档p_plan_task_detail表完成========");
}
......@@ -2467,6 +2471,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return d;
}).collect(Collectors.toList());
repositoryTs.batchSaveBySharding(collect);
planTaskMapper.truncateTable("p_check");
log.info("归档p_check表完成========");
}
......@@ -2480,6 +2485,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return d;
}).collect(Collectors.toList());
repositoryTs.batchSaveBySharding(collect);
planTaskMapper.truncateTable("p_check_input");
log.info("归档p_check_input表完成========");
}
......@@ -2494,6 +2500,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}).collect(Collectors.toList());
repositoryTs.batchSaveBySharding(collect);
planTaskMapper.truncateTable("p_check_shot");
log.info("归档p_check_shot表完成========");
}
......
//package com.yeejoin.amos.patrol.config;
//
//
//import lombok.Getter;
//import lombok.Setter;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.util.Assert;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import javax.sql.DataSource;
//import java.sql.Connection;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.sql.Statement;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author liran
// */
//@Slf4j
//@Setter
//@Getter
//@Component
//public class TableCreate {
//
// @Resource
// private ShardingSphereDataSource dataSource;
//
// Map<String, Object> createdTables = new HashMap<>();
// @Value("${shardingsphere.create.tables.num:10}")
// private String num;
//
// private String PLAN_TASK = "p_plan_task";
// private String PLAN_TASK_HISTORY = "p_plan_task_history_";
//
// private String PLAN_TASK_DETAIL = "p_plan_task_detail";
// private String PLAN_TASK_DETAIL_HISTORY = "p_plan_task_detail_history_";
//
// private String P_CHECK = "p_check";
// private String P_CHECK_HISTORY = "p_check_history_";
//
// private String P_CHECK_INPUT = "p_check_input";
// private String P_CHECK_INPUT_HISTORY = "p_check_input_history_";
//
// private String P_CHECK_SHOT = "p_check_shot";
// private String P_CHECK_SHOT_HISTORY = "p_check_shot_history_";
//
// private String DB = "amos_tzs_biz.";
//
//
// @PostConstruct
// public void init() {
// for(int i = 1; i<=Integer.parseInt(num); i++) {
// createNeedTime(PLAN_TASK,DB,PLAN_TASK_HISTORY+i);
// }
// for(int i = 1; i<=Integer.parseInt(num); i++) {
// createNeedTime(PLAN_TASK_DETAIL,DB,PLAN_TASK_DETAIL_HISTORY+i);
// }
// for(int i = 1; i<=Integer.parseInt(num); i++) {
// createNeedTime(P_CHECK,DB,P_CHECK_HISTORY+i);
// }
// for(int i = 1; i<=Integer.parseInt(num); i++) {
// createNeedTime(P_CHECK_INPUT,DB,P_CHECK_INPUT_HISTORY+i);
// }
// for(int i = 1; i<=Integer.parseInt(num); i++) {
// createNeedTime(P_CHECK_SHOT,DB,P_CHECK_SHOT_HISTORY+i);
// }
// }
//
//
// private void createNeedTime(String table, String db, String create) {
// DataSource dataSource = this.dataSource;
// String sql = "SHOW CREATE TABLE " + table;
// String existSql = "select * from information_schema.tables where table_name ='" + table + "'; ";
// doCreate(dataSource, sql, existSql, create, db, 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;
// Connection conn = null;
// Statement stmt = null;
// try {
// conn = dataSource.getConnection().getMetaData().getConnection();
// stmt = conn.createStatement();
// ResultSet resultSet = stmt.executeQuery(existSql);
// Assert.isTrue(resultSet.next(), msg + "初始化表不存在");
//
// ResultSet resTable = stmt.executeQuery(sql);
// Assert.isTrue(resTable.next(), msg + "初始化表不存在");
// String existTableName = resTable.getString(1);
// String createSqlOrigin = resTable.getString(2);
// // log.info(existTableName, createSqlOrigin);
//
// String existSqlNew = StringUtils.replaceOnce(existSql, existTableName, create);
// ResultSet executeQuery = stmt.executeQuery(existSqlNew);
// if (executeQuery.next()) {
// log.info("table exist :" + msg);
// } else {
// 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");
// if (0 == stmt.executeUpdate(creatsql)) {
// log.info(msg + "success !");
//
// } else {
// log.error(msg + "fail !");
// }
// }
// } catch (Exception e) {
// log.error("create table fail error : {} ", e.getMessage());
// } finally {
// if (stmt != null) {
// try {
// stmt.close();
// } catch (SQLException e) {
// log.error("SQLException", e);
// }
// }
// if (conn != null) {
// try {
// conn.close();
// } catch (SQLException e) {
// log.error("SQLException", e);
// }
// }
// }
// }
//
//}
package com.yeejoin.amos.patrol.config;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
/**
* @author liran
*/
@Slf4j
@Setter
@Getter
@Component
//@DS(DataSourceConfiguration.SHARDING_DATA_SOURCE_NAME)
public class TableCreate {
@Resource
private DataSource dataSource;
Map<String, Object> createdTables = new HashMap<>();
@Value("${shardingsphere.create.tables.num:10}")
private String num;
private String PLAN_TASK = "p_plan_task";
private String PLAN_TASK_HISTORY = "p_plan_task_history_";
private String PLAN_TASK_DETAIL = "p_plan_task_detail";
private String PLAN_TASK_DETAIL_HISTORY = "p_plan_task_detail_history_";
private String P_CHECK = "p_check";
private String P_CHECK_HISTORY = "p_check_history_";
private String P_CHECK_INPUT = "p_check_input";
private String P_CHECK_INPUT_HISTORY = "p_check_input_history_";
private String P_CHECK_SHOT = "p_check_shot";
private String P_CHECK_SHOT_HISTORY = "p_check_shot_history_";
private String DB = "amos_tzs_biz.";
@PostConstruct
public void init() {
for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(PLAN_TASK,DB,PLAN_TASK_HISTORY+i);
}
for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(PLAN_TASK_DETAIL,DB,PLAN_TASK_DETAIL_HISTORY+i);
}
for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK,DB,P_CHECK_HISTORY+i);
}
for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK_INPUT,DB,P_CHECK_INPUT_HISTORY+i);
}
for(int i = 1; i<=Integer.parseInt(num); i++) {
createNeedTime(P_CHECK_SHOT,DB,P_CHECK_SHOT_HISTORY+i);
}
}
private void createNeedTime(String table, String db, String create) {
DataSource dataSource = this.dataSource;
String sql = "SHOW CREATE TABLE " + table;
String existSql = "select * from information_schema.tables where table_name ='" + table + "'; ";
doCreate(dataSource, sql, existSql, create, db, 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;
Connection conn = null;
Statement stmt = null;
try {
conn = dataSource.getConnection().getMetaData().getConnection();
stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery(existSql);
Assert.isTrue(resultSet.next(), msg + "初始化表不存在");
ResultSet resTable = stmt.executeQuery(sql);
Assert.isTrue(resTable.next(), msg + "初始化表不存在");
String existTableName = resTable.getString(1);
String createSqlOrigin = resTable.getString(2);
// log.info(existTableName, createSqlOrigin);
String existSqlNew = StringUtils.replaceOnce(existSql, existTableName, create);
ResultSet executeQuery = stmt.executeQuery(existSqlNew);
if (executeQuery.next()) {
log.info("table exist :" + msg);
} else {
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");
if (0 == stmt.executeUpdate(creatsql)) {
log.info(msg + "success !");
} else {
log.error(msg + "fail !");
}
}
} catch (Exception e) {
log.error("create table fail error : {} ", e.getMessage());
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.error("SQLException", e);
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
log.error("SQLException", e);
}
}
}
}
}
......@@ -1711,6 +1711,9 @@
no_risk_end = no_risk_end + #{noRiskEnd}
where org_code = #{orgCode} AND check_time = #{checkTime}
</update>
<update id="truncateTable">
TRUNCATE ${tableName};
</update>
<select id="selectPlanTaskIdList" resultType="java.lang.String">
SELECT
......
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