用户、课程修改
This commit is contained in:
@@ -14,15 +14,17 @@ public class DataMigrationUtil extends Thread {
|
|||||||
|
|
||||||
Map map;
|
Map map;
|
||||||
int i;
|
int i;
|
||||||
|
Connection fzdsconn;
|
||||||
|
|
||||||
public DataMigrationUtil(Map map,int i){
|
public DataMigrationUtil(Map map,int i,Connection fzdsconn){
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.i = i;
|
this.i = i;
|
||||||
|
this.fzdsconn = fzdsconn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
catalogue();
|
// catalogue();
|
||||||
// courseCatalogue();
|
// courseCatalogue();
|
||||||
// courseCatalogueChapter();
|
// courseCatalogueChapter();
|
||||||
// courseCatalogueChapterVideo();
|
// courseCatalogueChapterVideo();
|
||||||
@@ -36,7 +38,7 @@ public class DataMigrationUtil extends Thread {
|
|||||||
Connection yljkconn = DriverManager.getConnection(
|
Connection yljkconn = DriverManager.getConnection(
|
||||||
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
|
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
|
||||||
"yljkmaster", "Wu751019!@");
|
"yljkmaster", "Wu751019!@");
|
||||||
PreparedStatement statement = yljkconn.prepareStatement("select * from t_curriculum_catalogue where valid = 1 and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid is null) and courseFee like '%,%' ");
|
PreparedStatement statement = yljkconn.prepareStatement("select * from t_curriculum_catalogue where valid = 1 and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid is null) and (courseFee like '%,%' or courseFee = '0' or poid = '00000000000000000000000000000070' )");
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
List<Map> list = new ArrayList();
|
List<Map> list = new ArrayList();
|
||||||
while(resultSet.next()){
|
while(resultSet.next()){
|
||||||
@@ -117,33 +119,43 @@ public class DataMigrationUtil extends Thread {
|
|||||||
System.out.println("===== 开始插入数据 =====");
|
System.out.println("===== 开始插入数据 =====");
|
||||||
int res = 0;
|
int res = 0;
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(
|
PreparedStatement preparedStatement = connection.prepareStatement(
|
||||||
"INSERT ignore INTO course_catalogue (course_id,title,half_fee,fee,create_time) VALUES (?,?,?,?,?)");
|
"INSERT ignore INTO course_catalogue (type,course_id,title,half_fee,fee,create_time) VALUES (?,?,?,?,?,?)");
|
||||||
for (int q=1;q<=fzdslist.size(); q++){
|
for (int q=1;q<=fzdslist.size(); q++){
|
||||||
String selectSql = "select * from t_curriculum_catalogue where valid = 1 and poid = '"+fzdslist.get(q-1).get("uid")+"'";
|
String selectSql = "select ccp.poid ppoid,cc.* from t_curriculum_catalogue cc left join t_curriculum_catalogue ccp on cc.poid = ccp.oid where ccp.valid = 1 and cc.valid = 1 and cc.poid = '"+fzdslist.get(q-1).get("uid")+"'";
|
||||||
PreparedStatement statement = yljkconn.prepareStatement(selectSql);
|
PreparedStatement statement = yljkconn.prepareStatement(selectSql);
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
Map map = new HashMap();
|
Map map = new HashMap();
|
||||||
while(resultSet.next()){
|
while(resultSet.next()){
|
||||||
map.put("title",resultSet.getString("title"));
|
String halfFee = "";
|
||||||
map.put("halfFee",resultSet.getString("courseFee").split(",")[0]);
|
String fee = "";
|
||||||
map.put("fee",resultSet.getString("courseFee").split(",")[1]);
|
if (resultSet.getString("courseFee")!=null&&resultSet.getString("courseFee").contains(",")){
|
||||||
map.put("createDate",resultSet.getString("createDate"));
|
halfFee = resultSet.getString("courseFee").split(",")[0];
|
||||||
if (map.size() > 0){
|
fee = resultSet.getString("courseFee").split(",")[1];
|
||||||
preparedStatement.setString(1,fzdslist.get(q-1).get("id").toString());
|
}else if (resultSet.getString("courseFee")!=null&&"0".equals(resultSet.getString("courseFee"))){
|
||||||
preparedStatement.setString(2,map.get("title").toString());
|
halfFee = "0";
|
||||||
preparedStatement.setString(3,map.get("halfFee").toString());
|
fee = "0";
|
||||||
preparedStatement.setString(4,map.get("fee").toString());
|
}
|
||||||
preparedStatement.setString(5,map.get("createDate").toString());
|
if ("0".equals(resultSet.getString("courseFee"))){
|
||||||
// 添加到批处理中
|
preparedStatement.setInt(1,0);
|
||||||
preparedStatement.addBatch();
|
}else if ("00000000000000000000000000000070".equals(resultSet.getString("ppoid"))){
|
||||||
res++;
|
preparedStatement.setInt(1,2);
|
||||||
if (res % 5000 == 0) {
|
}else {
|
||||||
long startTime1 = System.currentTimeMillis();
|
preparedStatement.setInt(1,1);
|
||||||
preparedStatement.executeBatch();
|
}
|
||||||
connection.commit();
|
preparedStatement.setString(2,fzdslist.get(q-1).get("id").toString());
|
||||||
long spendTime1 = System.currentTimeMillis()-startTime1;
|
preparedStatement.setString(3,resultSet.getString("title"));
|
||||||
System.out.println("成功插入第"+ res +" 条数据,耗时:"+spendTime1+"毫秒");
|
preparedStatement.setString(4,halfFee);
|
||||||
}
|
preparedStatement.setString(5,fee);
|
||||||
|
preparedStatement.setString(6,resultSet.getString("createDate"));
|
||||||
|
// 添加到批处理中
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
res++;
|
||||||
|
if (res % 5000 == 0) {
|
||||||
|
long startTime1 = System.currentTimeMillis();
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
long spendTime1 = System.currentTimeMillis()-startTime1;
|
||||||
|
System.out.println("成功插入第"+ res +" 条数据,耗时:"+spendTime1+"毫秒");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
@@ -315,6 +327,7 @@ public class DataMigrationUtil extends Thread {
|
|||||||
|
|
||||||
public static void user(){
|
public static void user(){
|
||||||
try {
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
Connection yljkconn = DriverManager.getConnection(
|
Connection yljkconn = DriverManager.getConnection(
|
||||||
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
|
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
|
||||||
"yljkmaster", "Wu751019!@");
|
"yljkmaster", "Wu751019!@");
|
||||||
@@ -339,12 +352,16 @@ public class DataMigrationUtil extends Thread {
|
|||||||
resultSet.close();
|
resultSet.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
yljkconn.close();
|
yljkconn.close();
|
||||||
|
Connection fzdsconn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
// 1、创建服务,创建线程池
|
// 1、创建服务,创建线程池
|
||||||
ExecutorService service = Executors.newFixedThreadPool(50);
|
ExecutorService service = Executors.newFixedThreadPool(50);
|
||||||
for (int i=1;i<=list.size(); i++){
|
for (int i=0;i<list.size(); i++){
|
||||||
DataMigrationUtil d1 = new DataMigrationUtil(list.get(i),i);
|
DataMigrationUtil d1 = new DataMigrationUtil(list.get(i),i+1,fzdsconn);
|
||||||
service.execute(d1);
|
service.execute(d1);
|
||||||
}
|
}
|
||||||
|
System.out.println("---已插入数据");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("Error: " + e.getMessage());
|
System.out.println("Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -354,13 +371,10 @@ public class DataMigrationUtil extends Thread {
|
|||||||
public void run(){
|
public void run(){
|
||||||
try {
|
try {
|
||||||
if (i % 1000 == 0) {
|
if (i % 1000 == 0) {
|
||||||
System.out.println("---已插入数据"+i);
|
System.out.println("---已插入数据"+i+"--"+ DateUtil.format(new Date(),"YYYY-MM-dd HH:mm:ss"));
|
||||||
}
|
}
|
||||||
String userId = "";
|
String userId = "";
|
||||||
BigDecimal userBalance = new BigDecimal(0);
|
BigDecimal userBalance = new BigDecimal(0);
|
||||||
Connection fzdsconn = DriverManager.getConnection(
|
|
||||||
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
|
||||||
"nuttyreading", "Wu751019!");
|
|
||||||
PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and yljk_oid = '"+map.get("oid")+"' ");
|
PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and yljk_oid = '"+map.get("oid")+"' ");
|
||||||
ResultSet oidResultSet = oidStatements.executeQuery();
|
ResultSet oidResultSet = oidStatements.executeQuery();
|
||||||
//已绑定过id
|
//已绑定过id
|
||||||
@@ -445,7 +459,6 @@ public class DataMigrationUtil extends Thread {
|
|||||||
transactionDetailStatement.execute();
|
transactionDetailStatement.execute();
|
||||||
transactionDetailStatement.close();
|
transactionDetailStatement.close();
|
||||||
}
|
}
|
||||||
fzdsconn.close();
|
|
||||||
}catch (Exception ee){
|
}catch (Exception ee){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user