diff --git a/src/main/java/com/peanut/common/utils/DataMigrationUtil.java b/src/main/java/com/peanut/common/utils/DataMigrationUtil.java index f5ec8679..bb8e69d1 100644 --- a/src/main/java/com/peanut/common/utils/DataMigrationUtil.java +++ b/src/main/java/com/peanut/common/utils/DataMigrationUtil.java @@ -311,7 +311,7 @@ public class DataMigrationUtil { Connection yljkconn = DriverManager.getConnection( "jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?", "yljkmaster", "Wu751019!@"); - PreparedStatement statement = yljkconn.prepareStatement("select oid,cellPhone,nameCN,nickName,superVIP,point,pointByJF,payStatus,paydate,payValidDate from t_customer where valid = 1 "); + PreparedStatement statement = yljkconn.prepareStatement("select oid,cellPhone,nameCN,nickName,icons,superVIP,point,pointByJF,payStatus,paydate,payValidDate from t_customer where valid = 1 and cellphone != '' and cellphone is not null "); ResultSet resultSet = statement.executeQuery(); List list = new ArrayList(); while(resultSet.next()){ @@ -320,6 +320,7 @@ public class DataMigrationUtil { map.put("cellPhone",resultSet.getString("cellPhone")); map.put("nameCN",resultSet.getString("nameCN")); map.put("nickName",resultSet.getString("nickName")); + map.put("icons",resultSet.getString("icons")); map.put("superVIP",resultSet.getString("superVIP")); map.put("point",resultSet.getString("point")); map.put("pointByJF",resultSet.getString("pointByJF")); @@ -330,42 +331,78 @@ public class DataMigrationUtil { } resultSet.close(); statement.close(); + int q = 0; + int w = 0; + int e = 0; + int r = 0; + PreparedStatement telInsertStatement = fzdsconn.prepareStatement( + "INSERT ignore INTO user_copy1 (name,avatar,nickname,tel,vip,peanut_coin,jf,yljk_oid) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement userVipStatement = fzdsconn.prepareStatement( + "INSERT ignore INTO user_vip_copy1 (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)"); for (int i=1;i<=list.size(); i++){ + String userId = ""; + System.out.println(i+"---"+list.get(i).get("nameCN")); //已绑定过 PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and yljk_oid = '"+list.get(i).get("oid")+"' "); ResultSet oidResultSet = oidStatements.executeQuery(); if (oidResultSet.next()){ - PreparedStatement oidUpdateStatement = fzdsconn.prepareStatement("update user_copy1 set " + - "name = if(isnull(name),"+list.get(i).get("nameCN")+") , nickname = if(isnull(nickname),"+list.get(i).get("nickName")+") ," + - "tel = if(isnull(tel),"+list.get(i).get("cellPhone")+") ," + - "vip= "+list.get(i).get("payStatus")+" ,peanut_coin = peanut_coin + "+list.get(i).get("point")+" , jf = jf + "+list.get(i).get("pointByJF")+" where id = "+oidResultSet.getString("id")+""); - oidUpdateStatement.executeUpdate(); - if (list.get(i).get("payValidDate")!=null){ - PreparedStatement oidInsertStatement = fzdsconn.prepareStatement( - "INSERT ignore INTO user_vip_copy1 (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)"); - oidInsertStatement.setString(1,oidResultSet.getString("id")); - oidInsertStatement.setString(2,list.get(i).get("payStatus").toString()); - oidInsertStatement.setString(3,list.get(i).get("paydate").toString()); - oidInsertStatement.setString(4,list.get(i).get("payValidDate").toString()); - if (DateUtil.compare(DateUtil.parseDate(list.get(i).get("payValidDate").toString()),new Date())>0){ - oidInsertStatement.setString(5,"0"); - }else { - oidInsertStatement.setString(5,"1"); - } - oidUpdateStatement.execute(); - } + String sql = "update user_copy1 set " + + "name = if(isnull(name),'"+list.get(i).get("nameCN")+"',name) , nickname = if(isnull(nickname),'"+list.get(i).get("nickName")+"',nickname) ," + + "tel = if(isnull(tel),'"+list.get(i).get("cellPhone")+"',tel) ," + + "vip= "+list.get(i).get("payStatus")+" ,peanut_coin = peanut_coin + "+list.get(i).get("point")+" , jf = jf + "+list.get(i).get("pointByJF")+" where id = "+oidResultSet.getString("id")+""; + PreparedStatement oidUpdateStatement = fzdsconn.prepareStatement(sql); + userId = oidResultSet.getString("id"); + oidUpdateStatement.executeBatch(); }else { //未绑定过,用电话查询 PreparedStatement telStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and tel = '"+list.get(i).get("cellPhone")+"' "); ResultSet telResultSet = telStatements.executeQuery(); if (telResultSet.next()){ - + String sql = "update user_copy1 set yljk_oid = '" + list.get(i).get("oid") +"',"+ + " name = if(isnull(name),'"+list.get(i).get("nameCN")+"',name) , nickname = if(isnull(nickname),'"+list.get(i).get("nickName")+"',nickname) ," + + "vip= "+list.get(i).get("payStatus")+" ,peanut_coin = peanut_coin + "+list.get(i).get("point")+" , jf = jf + "+list.get(i).get("pointByJF")+" where tel = '"+list.get(i).get("cellPhone")+"'"; + PreparedStatement telUpdateStatement = fzdsconn.prepareStatement(sql); + userId = telResultSet.getString("id"); + telUpdateStatement.executeBatch(); + }else { + telInsertStatement.setString(1,list.get(i).get("nameCN")==null?"":list.get(i).get("nameCN").toString()); + telInsertStatement.setString(2,list.get(i).get("icons")==null?"":list.get(i).get("icons").toString()); + telInsertStatement.setString(3,list.get(i).get("nickName")==null?"":list.get(i).get("nickName").toString()); + telInsertStatement.setString(4,list.get(i).get("cellPhone")==null?"":list.get(i).get("cellPhone").toString()); + telInsertStatement.setString(5,list.get(i).get("payStatus")==null?"":list.get(i).get("payStatus").toString()); + telInsertStatement.setString(6,list.get(i).get("point")==null?"":list.get(i).get("point").toString()); + telInsertStatement.setString(7,list.get(i).get("pointByJF")==null?"":list.get(i).get("pointByJF").toString()); + telInsertStatement.setString(8,list.get(i).get("oid")==null?"":list.get(i).get("oid").toString()); + // 添加到批处理中 + telInsertStatement.addBatch(); + e++; + if (e % 1000 == 0) { + telInsertStatement.executeBatch(); + } + } + } + if (list.get(i).get("paydate")!=null&&list.get(i).get("payValidDate")!=null){ + userVipStatement.setString(1,userId); + userVipStatement.setString(2,list.get(i).get("payStatus").toString()); + userVipStatement.setString(3,list.get(i).get("paydate").toString()); + userVipStatement.setString(4,list.get(i).get("payValidDate").toString()); + if (DateUtil.compare(DateUtil.parseDate(list.get(i).get("payValidDate").toString()),new Date())>0){ + userVipStatement.setString(5,"0"); + }else { + userVipStatement.setString(5,"1"); + } + userVipStatement.execute(); + // 添加到批处理中 + userVipStatement.addBatch(); + r++; + if (r % 1000 == 0) { + userVipStatement.executeBatch(); } } } - - - + telInsertStatement.executeBatch(); + userVipStatement.executeBatch(); } catch (SQLException e) { System.out.println("Error: " + e.getMessage()); }