|
|
@@ -1,6 +1,8 @@
|
|
|
package com.usky.service;
|
|
|
|
|
|
+import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
|
|
import com.usky.utils.ListUtil;
|
|
|
+import org.aspectj.weaver.ast.Var;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -30,13 +32,16 @@ public class StartServiceImpl implements StartService {
|
|
|
@Autowired
|
|
|
@Qualifier("jdbcTemplate187")
|
|
|
private JdbcTemplate jdbcTemplate187;
|
|
|
+
|
|
|
@Override
|
|
|
public void start(String tableName, String time) {
|
|
|
String age = redisTemplate.opsForValue().get("age");
|
|
|
List<Map<String, Object>> resList = query187Tables(tableName);
|
|
|
- Boolean aBoolean = creatTable(resList,time);
|
|
|
+ Boolean aBoolean = creatTable(resList, time);
|
|
|
}
|
|
|
+
|
|
|
public Boolean creatTable(List<Map<String, Object>> resList, String time) {
|
|
|
+
|
|
|
if (ListUtil.isNotBlank(resList)) {
|
|
|
Map<String, Object> tablNameMap = resList.get(0);
|
|
|
String tableName = (String) tablNameMap.get("Table");
|
|
|
@@ -46,34 +51,72 @@ public class StartServiceImpl implements StartService {
|
|
|
if (ListUtil.isBlank(maps)) {
|
|
|
jdbcTemplate118.execute(tableSql);
|
|
|
}
|
|
|
- String querySql = "select * from " + tableName + " as t where t."+time+" <(DATE_ADD(now(),INTERVAL -1 month))";
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- List<Map<String, Object>> data187 = jdbcTemplate187.queryForList(querySql);
|
|
|
- for (Map<String, Object> objectMap : data187) {
|
|
|
- for (String s : objectMap.keySet()) {
|
|
|
- if (s.equals("id")){
|
|
|
- sb.append(objectMap.get(s));
|
|
|
- }else {
|
|
|
- sb.append("'" + objectMap.get(s) + "'");
|
|
|
+ String queryCount = "select count(*) from " + tableName + " as t where t." + time + " <(DATE_ADD(now(),INTERVAL -1 month))";
|
|
|
+ Map<String, Object> countMap = jdbcTemplate187.queryForMap(queryCount);
|
|
|
+ Long count = (Long) countMap.get("count(*)");
|
|
|
+ int i = 10000;
|
|
|
+ if (count / i != 0) {
|
|
|
+ for (int j = 0; j < count / i; j++) {
|
|
|
+ String querySql = "select * from " + tableName + " as t where t." + time + " <(DATE_ADD(now(),INTERVAL -1 month)) limit 10000";
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ List<Map<String, Object>> data187 = jdbcTemplate187.queryForList(querySql);
|
|
|
+ for (Map<String, Object> objectMap : data187) {
|
|
|
+ for (String s : objectMap.keySet()) {
|
|
|
+ if (s.equals("id")) {
|
|
|
+ sb.append(objectMap.get(s));
|
|
|
+ } else {
|
|
|
+ sb.append("'" + objectMap.get(s) + "'");
|
|
|
+ }
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
+ String inSql = "INSERT INTO " + tableName + " VALUES (" + sb.toString() + ")";
|
|
|
+ int update = jdbcTemplate118.update(inSql);
|
|
|
+ if (update != 0) {
|
|
|
+ String delSql = "delete from " + tableName + " where id= " + objectMap.get("id") + "";
|
|
|
+ int update1 = jdbcTemplate187.update(delSql);
|
|
|
+ }
|
|
|
+ sb.setLength(0);
|
|
|
}
|
|
|
- sb.append(",");
|
|
|
}
|
|
|
- sb.deleteCharAt(sb.length() - 1);
|
|
|
- String inSql = "INSERT INTO " + tableName + " VALUES (" + sb.toString() + ")";
|
|
|
- int update = jdbcTemplate118.update(inSql);
|
|
|
- if (update!=0){
|
|
|
- String delSql="delete from "+tableName+" where id= "+objectMap.get("id")+"";
|
|
|
- int update1 = jdbcTemplate187.update(delSql);
|
|
|
+
|
|
|
+ }else {
|
|
|
+ String querySql = "select * from " + tableName + " as t where t." + time + " <(DATE_ADD(now(),INTERVAL -1 month))";
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ List<Map<String, Object>> data187 = jdbcTemplate187.queryForList(querySql);
|
|
|
+ for (Map<String, Object> objectMap : data187) {
|
|
|
+ for (String s : objectMap.keySet()) {
|
|
|
+ if (s.equals("id")) {
|
|
|
+ sb.append(objectMap.get(s));
|
|
|
+ } else {
|
|
|
+ sb.append("'" + objectMap.get(s) + "'");
|
|
|
+ }
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
+ String inSql = "INSERT INTO " + tableName + " VALUES (" + sb.toString() + ")";
|
|
|
+ int update = jdbcTemplate118.update(inSql);
|
|
|
+ if (update != 0) {
|
|
|
+ String delSql = "delete from " + tableName + " where id= " + objectMap.get("id") + "";
|
|
|
+ int update1 = jdbcTemplate187.update(delSql);
|
|
|
+ }
|
|
|
+ sb.setLength(0);
|
|
|
}
|
|
|
- sb.setLength(0);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
public List<Map<String, Object>> query187Tables(String tableName) {
|
|
|
String sql = "show create table " + tableName + "";
|
|
|
return jdbcTemplate187.queryForList(sql);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ public static void main(String[] args) {
|
|
|
+ long l = 5656;
|
|
|
+ int i = 10000;
|
|
|
+ long l1 = l / i;
|
|
|
+ System.out.println("l1 = " + l1);
|
|
|
}
|
|
|
}
|