Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
eb0fc377
Commit
eb0fc377
authored
Dec 04, 2023
by
lisong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据归档添加删除逻辑
parent
d9420f49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
135 deletions
+149
-135
PlanTaskMapper.java
...ejoin/amos/patrol/business/dao/mapper/PlanTaskMapper.java
+3
-0
PlanTaskServiceImpl.java
...mos/patrol/business/service/impl/PlanTaskServiceImpl.java
+7
-0
TableCreate.java
...main/java/com/yeejoin/amos/patrol/config/TableCreate.java
+136
-135
dbTemplate_plan_task.xml
...biz/src/main/resources/db/mapper/dbTemplate_plan_task.xml
+3
-0
No files found.
amos-boot-system-tzs/amos-boot-module-tzspatrol/amos-boot-module-tzspatrol-biz/src/main/java/com/yeejoin/amos/patrol/business/dao/mapper/PlanTaskMapper.java
View file @
eb0fc377
...
@@ -291,6 +291,9 @@ public interface PlanTaskMapper extends BaseMapper {
...
@@ -291,6 +291,9 @@ public interface PlanTaskMapper extends BaseMapper {
List
<
Check
>
findCheck
();
List
<
Check
>
findCheck
();
void
truncateTable
(
@Param
(
"tableName"
)
String
tableName
);
List
<
CheckInput
>
findCheckInput
();
List
<
CheckInput
>
findCheckInput
();
List
<
CheckShot
>
findCheckShot
();
List
<
CheckShot
>
findCheckShot
();
...
...
amos-boot-system-tzs/amos-boot-module-tzspatrol/amos-boot-module-tzspatrol-biz/src/main/java/com/yeejoin/amos/patrol/business/service/impl/PlanTaskServiceImpl.java
View file @
eb0fc377
...
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
...
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.dynamic.datasource.annotation.DS
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Stopwatch
;
import
com.google.common.base.Stopwatch
;
import
com.sun.corba.se.impl.activation.RepositoryImpl
;
import
com.sun.corba.se.impl.activation.RepositoryImpl
;
...
@@ -38,6 +39,7 @@ import com.yeejoin.amos.patrol.business.util.Toke;
...
@@ -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.util.WordTemplateUtils
;
import
com.yeejoin.amos.patrol.business.vo.*
;
import
com.yeejoin.amos.patrol.business.vo.*
;
import
com.yeejoin.amos.patrol.common.enums.*
;
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.request.CommonPageable
;
import
com.yeejoin.amos.patrol.core.common.response.AppCheckInputRespone
;
import
com.yeejoin.amos.patrol.core.common.response.AppCheckInputRespone
;
import
com.yeejoin.amos.patrol.core.common.response.AppPointCheckRespone
;
import
com.yeejoin.amos.patrol.core.common.response.AppPointCheckRespone
;
...
@@ -2441,6 +2443,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
...
@@ -2441,6 +2443,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
repositoryTs
.
batchSaveBySharding
(
collect
);
repositoryTs
.
batchSaveBySharding
(
collect
);
planTaskMapper
.
truncateTable
(
"p_plan_task"
);
log
.
info
(
"归档p_plan_task表完成========"
);
log
.
info
(
"归档p_plan_task表完成========"
);
}
}
...
@@ -2454,6 +2457,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
...
@@ -2454,6 +2457,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return
d
;
return
d
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
repositoryTs
.
batchSaveBySharding
(
collect
);
repositoryTs
.
batchSaveBySharding
(
collect
);
planTaskMapper
.
truncateTable
(
"p_plan_task_detail"
);
log
.
info
(
"归档p_plan_task_detail表完成========"
);
log
.
info
(
"归档p_plan_task_detail表完成========"
);
}
}
...
@@ -2467,6 +2471,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
...
@@ -2467,6 +2471,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return
d
;
return
d
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
repositoryTs
.
batchSaveBySharding
(
collect
);
repositoryTs
.
batchSaveBySharding
(
collect
);
planTaskMapper
.
truncateTable
(
"p_check"
);
log
.
info
(
"归档p_check表完成========"
);
log
.
info
(
"归档p_check表完成========"
);
}
}
...
@@ -2480,6 +2485,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
...
@@ -2480,6 +2485,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
return
d
;
return
d
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
repositoryTs
.
batchSaveBySharding
(
collect
);
repositoryTs
.
batchSaveBySharding
(
collect
);
planTaskMapper
.
truncateTable
(
"p_check_input"
);
log
.
info
(
"归档p_check_input表完成========"
);
log
.
info
(
"归档p_check_input表完成========"
);
}
}
...
@@ -2494,6 +2500,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
...
@@ -2494,6 +2500,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
repositoryTs
.
batchSaveBySharding
(
collect
);
repositoryTs
.
batchSaveBySharding
(
collect
);
planTaskMapper
.
truncateTable
(
"p_check_shot"
);
log
.
info
(
"归档p_check_shot表完成========"
);
log
.
info
(
"归档p_check_shot表完成========"
);
}
}
...
...
amos-boot-system-tzs/amos-boot-module-tzspatrol/amos-boot-module-tzspatrol-biz/src/main/java/com/yeejoin/amos/patrol/config/TableCreate.java
View file @
eb0fc377
//package com.yeejoin.amos.patrol.config;
package
com
.
yeejoin
.
amos
.
patrol
.
config
;
//
//
//import lombok.Getter;
import
com.baomidou.dynamic.datasource.annotation.DS
;
//import lombok.Setter;
import
lombok.Getter
;
//import lombok.extern.slf4j.Slf4j;
import
lombok.Setter
;
//import org.apache.commons.lang3.StringUtils;
import
lombok.extern.slf4j.Slf4j
;
//import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import
org.apache.commons.lang3.StringUtils
;
//
//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 {
//@DS(DataSourceConfiguration.SHARDING_DATA_SOURCE_NAME)
//
public
class
TableCreate
{
// @Resource
// private ShardingSphereDataSource dataSource;
@Resource
//
private
DataSource
dataSource
;
// Map<String, Object> createdTables = new HashMap<>();
// @Value("${shardingsphere.create.tables.num:10}")
Map
<
String
,
Object
>
createdTables
=
new
HashMap
<>();
// private String num;
@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
=
"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
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
=
"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_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
P_CHECK_SHOT
=
"p_check_shot"
;
//
private
String
P_CHECK_SHOT_HISTORY
=
"p_check_shot_history_"
;
// private String DB = "amos_tzs_biz.";
//
private
String
DB
=
"amos_tzs_biz."
;
//
// @PostConstruct
// public void init() {
@PostConstruct
// for(int i = 1; i<=Integer.parseInt(num); i++) {
public
void
init
()
{
// createNeedTime(PLAN_TASK,DB,PLAN_TASK_HISTORY+i);
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
(
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
,
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_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);
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;
private
void
createNeedTime
(
String
table
,
String
db
,
String
create
)
{
// String sql = "SHOW CREATE TABLE " + table;
DataSource
dataSource
=
this
.
dataSource
;
// String existSql = "select * from information_schema.tables where table_name ='" + table + "'; ";
String
sql
=
"SHOW CREATE TABLE "
+
table
;
// doCreate(dataSource, sql, existSql, create, db, 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;
private
void
doCreate
(
DataSource
dataSource
,
String
sql
,
String
existSql
,
String
create
,
String
db
,
String
table
)
{
// Connection conn = null;
String
msg
=
" create table: "
+
create
+
" origin table: "
+
table
+
" db: "
+
db
;
// Statement stmt = null;
Connection
conn
=
null
;
// try {
Statement
stmt
=
null
;
// conn = dataSource.getConnection().getMetaData().getConnection();
try
{
// stmt = conn.createStatement();
conn
=
dataSource
.
getConnection
().
getMetaData
().
getConnection
();
// ResultSet resultSet = stmt.executeQuery(existSql);
stmt
=
conn
.
createStatement
();
// Assert.isTrue(resultSet.next(), msg + "初始化表不存在");
ResultSet
resultSet
=
stmt
.
executeQuery
(
existSql
);
//
Assert
.
isTrue
(
resultSet
.
next
(),
msg
+
"初始化表不存在"
);
// ResultSet resTable = stmt.executeQuery(sql);
// Assert.isTrue(resTable.next(), msg + "初始化表不存在");
ResultSet
resTable
=
stmt
.
executeQuery
(
sql
);
// String existTableName = resTable.getString(1);
Assert
.
isTrue
(
resTable
.
next
(),
msg
+
"初始化表不存在"
);
// String createSqlOrigin = resTable.getString(2);
String
existTableName
=
resTable
.
getString
(
1
);
// // log.info(existTableName, createSqlOrigin);
String
createSqlOrigin
=
resTable
.
getString
(
2
);
//
// log.info(existTableName, createSqlOrigin);
// String existSqlNew = StringUtils.replaceOnce(existSql, existTableName, create);
// ResultSet executeQuery = stmt.executeQuery(existSqlNew);
String
existSqlNew
=
StringUtils
.
replaceOnce
(
existSql
,
existTableName
,
create
);
// if (executeQuery.next()) {
ResultSet
executeQuery
=
stmt
.
executeQuery
(
existSqlNew
);
// log.info("table exist :" + msg);
if
(
executeQuery
.
next
())
{
// } else {
log
.
info
(
"table exist :"
+
msg
);
// createSqlOrigin = createSqlOrigin.substring(0,createSqlOrigin.indexOf(";"));
}
else
{
// String creatsql = StringUtils.replace(createSqlOrigin, existTableName, create).replaceFirst(create, DB+create).replace("bigint(64)", "int8").replace("smallint(16)","int2");
createSqlOrigin
=
createSqlOrigin
.
substring
(
0
,
createSqlOrigin
.
indexOf
(
";"
));
// if (0 == stmt.executeUpdate(creatsql)) {
String
creatsql
=
StringUtils
.
replace
(
createSqlOrigin
,
existTableName
,
create
).
replaceFirst
(
create
,
DB
+
create
).
replace
(
"bigint(64)"
,
"int8"
).
replace
(
"smallint(16)"
,
"int2"
);
// log.info(msg + "success !");
if
(
0
==
stmt
.
executeUpdate
(
creatsql
))
{
//
log
.
info
(
msg
+
"success !"
);
// } else {
// log.error(msg + "fail !");
}
else
{
// }
log
.
error
(
msg
+
"fail !"
);
// }
}
// } catch (Exception e) {
}
// log.error("create table fail error : {} ", e.getMessage());
}
catch
(
Exception
e
)
{
// } finally {
log
.
error
(
"create table fail error : {} "
,
e
.
getMessage
());
// if (stmt != null) {
}
finally
{
// try {
if
(
stmt
!=
null
)
{
// stmt.close();
try
{
// } catch (SQLException e) {
stmt
.
close
();
// log.error("SQLException", e);
}
catch
(
SQLException
e
)
{
// }
log
.
error
(
"SQLException"
,
e
);
// }
}
// if (conn != null) {
}
// try {
if
(
conn
!=
null
)
{
// conn.close();
try
{
// } catch (SQLException e) {
conn
.
close
();
// log.error("SQLException", e);
}
catch
(
SQLException
e
)
{
// }
log
.
error
(
"SQLException"
,
e
);
// }
}
// }
}
// }
}
//
}
//}
}
amos-boot-system-tzs/amos-boot-module-tzspatrol/amos-boot-module-tzspatrol-biz/src/main/resources/db/mapper/dbTemplate_plan_task.xml
View file @
eb0fc377
...
@@ -1711,6 +1711,9 @@
...
@@ -1711,6 +1711,9 @@
no_risk_end = no_risk_end + #{noRiskEnd}
no_risk_end = no_risk_end + #{noRiskEnd}
where org_code = #{orgCode} AND check_time = #{checkTime}
where org_code = #{orgCode} AND check_time = #{checkTime}
</update>
</update>
<update
id=
"truncateTable"
>
TRUNCATE ${tableName};
</update>
<select
id=
"selectPlanTaskIdList"
resultType=
"java.lang.String"
>
<select
id=
"selectPlanTaskIdList"
resultType=
"java.lang.String"
>
SELECT
SELECT
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment