本地执行工具

This commit is contained in:
wuchunlei
2025-07-02 14:28:28 +08:00
parent 85d1fec512
commit 596922cf83
9 changed files with 2211 additions and 0 deletions

View File

@@ -0,0 +1,429 @@
package com.peanut.common.utils;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang.time.DateUtils;
import java.net.URL;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class UserCourseBuyUtil {
//批量开课
public static void main(String[] args) {
userEbookBuy250410();
// userCourseBuy();
// userEbookBuy();
// userCourseBuyShopProductCourse();
// userCourseBuyShopProductCourse22();
// userCourseBuyOnload();
// userCourseBuyOnload2();
// userVipUpdate();
}
public static void userEbookBuy250410() {
try {
Connection yljkConn = DriverManager.getConnection(
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
Connection fzdsConn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
int k=0;
// 关闭自动提交事务,改为手动提交
fzdsConn.setAutoCommit(false);
long startTime = System.currentTimeMillis();
long startTime1 = System.currentTimeMillis();
PreparedStatement addUserCourseBuyStatement = fzdsConn.prepareStatement(
"INSERT ignore INTO user_course_buy (user_id,course_id,catalogue_id,create_time,days,start_time,end_time,come) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement oldStatement = yljkConn.prepareStatement("select * from t_customer_taihu_class where valid = 1 and status = 10 and createDate > '2024-07-12' and description not like '%VIP%' ");
ResultSet oldResultSet = oldStatement.executeQuery();
int courseId = 0;
int courseCatalogueId = 0;
String catalogueTitle = "";
while(oldResultSet.next()){
k++;
String userOid = oldResultSet.getString("customerOid");
PreparedStatement userStatement = fzdsConn.prepareStatement("select * from user where del_flag = 0 and yljk_oid = '"+userOid+"'");
ResultSet userResultSet = userStatement.executeQuery();
while(userResultSet.next()){
boolean flag = true;
PreparedStatement userVipStatement = fzdsConn.prepareStatement("select * from user_vip where del_flag = 0 and state = 0 and user_id = "+userResultSet.getInt("id"));
ResultSet userVipResultSet = userVipStatement.executeQuery();
while(userVipResultSet.next()){
flag = false;
}
if (flag) {
PreparedStatement cataloguestatement = yljkConn.prepareStatement("" +
"select * from t_curriculum_catalogue where valid = 1 and oid = '"+oldResultSet.getString("taiHuClassOid")+"'");
ResultSet catalogueresultSet = cataloguestatement.executeQuery();
while (catalogueresultSet.next()) {
catalogueTitle = catalogueresultSet.getString("title");
PreparedStatement coursestatement = fzdsConn.prepareStatement("" +
"select * from course where uid = '"+catalogueresultSet.getString("poid")+"'");
ResultSet courseresultSet = coursestatement.executeQuery();
while (courseresultSet.next()) {
courseId = courseresultSet.getInt("id");
}
}
PreparedStatement coursecataloguestatement = fzdsConn.prepareStatement("" +
"select * from course_catalogue where del_flag = 0 and course_id = "+courseId+" and title = '"+catalogueTitle
+"'");
ResultSet coursecatalogueresultSet = coursecataloguestatement.executeQuery();
while (coursecatalogueresultSet.next()) {
courseCatalogueId = coursecatalogueresultSet.getInt("id");
}
addUserCourseBuyStatement.setInt(1,userResultSet.getInt("id"));
addUserCourseBuyStatement.setInt(2,courseId);
addUserCourseBuyStatement.setInt(3,courseCatalogueId);
addUserCourseBuyStatement.setTimestamp(4,oldResultSet.getTimestamp("createDate"));
addUserCourseBuyStatement.setInt(5,oldResultSet.getInt("studyDays")==0?365:oldResultSet.getInt("studyDays"));
addUserCourseBuyStatement.setTimestamp(6,oldResultSet.getTimestamp("startDate"));
if (oldResultSet.getTimestamp("startDate")==null){
addUserCourseBuyStatement.setString(7, null);
}else {
Date endDate = DateUtils.addDays(oldResultSet.getTimestamp("startDate"),oldResultSet.getInt("studyDays"));
addUserCourseBuyStatement.setTimestamp(7,Timestamp.valueOf(DateUtil.format(endDate,"yyyy-MM-dd HH:mm:ss")));
}
addUserCourseBuyStatement.setString(8,"yljk迁移");
addUserCourseBuyStatement.addBatch();
System.out.println(""+ k);
}
}
if (k % 1000 == 0) {
// 每1000条数据提交一次
addUserCourseBuyStatement.executeBatch();
fzdsConn.commit();
long spendTime1 = System.currentTimeMillis()-startTime1;
startTime1 = System.currentTimeMillis();
System.out.println("成功插入第 "+ k+" 条数据,耗时:"+spendTime1/1000+"");
}
}
// 处理剩余的数据
addUserCourseBuyStatement.executeBatch();
fzdsConn.commit();
fzdsConn.setAutoCommit(true);//在把自动提交打开
long spendTime = System.currentTimeMillis()-startTime;
System.out.println("成功插入"+k+"条数据,耗时:"+spendTime/1000+"");
} catch (Exception e) {
System.out.println(e);
}
}
public static void userEbookBuy() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement statement = fzdsconn.prepareStatement("" +
"select bo.user_id from buy_order_product bop " +
"left join buy_order bo on bo.order_id = bop.order_id " +
"where bop.product_id = 1637 and bo.del_flag = 0 and bo.order_status in (1,2,3) group by bo.user_id ");
ResultSet resultSet = statement.executeQuery();
PreparedStatement addUserEbookBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_ebook_buy (user_id,book_id) VALUES (?, ?)");
while(resultSet.next()){
int userId = resultSet.getInt("user_id");
addUserEbookBuyStatement.setInt(1,userId);
addUserEbookBuyStatement.setInt(2,247);
addUserEbookBuyStatement.addBatch();
}
addUserEbookBuyStatement.executeBatch();
} catch (Exception e) {
System.out.println(e);
}
}
public static void userCourseBuy() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
String str = "18026280912,18923221117,138999715789,13789860595,13958112970,18042322840,18822180212,18801800626,18182488636,13920824009,13810947856,15957915900,15704601021,13537736958,13130437779,18280337034,13608010972,13930682183,13304711384,15332055786,13524355516,13774496157,15389046616,15290224386,18924056976 ,13370556764,18681436632,15201163340,13858961234,15721570509,15972800166,13934534511,13560350715,13335013906,13623631189,15333566532,424023981,0410317573,13631384127,13533531792,15129799293,18035115008,13851639824,15022443770,13869945456,13570817083,6043741898,15999972127";
String[] tels = str.split(",");
for (String tel : tels) {
tel = tel.replace(" ","");
PreparedStatement statement = fzdsconn.prepareStatement("select * from user where tel like '%"+tel+"%' and del_flag=0 ");
ResultSet resultSet = statement.executeQuery();
List<Object> list = new ArrayList<>();
while(resultSet.next()){
list.add(resultSet.getString("id"));
}
if (list.size() == 0){
System.out.println(tel+"-无账号");
}else if (list.size() > 1){
System.out.println(tel+"-多账号");
}else {
PreparedStatement addUserCourseBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_course_buy (user_id,course_id,catalogue_id,days,come) VALUES (?, ?, ?, ?, ?)");
addUserCourseBuyStatement.setString(1,list.get(0).toString());
addUserCourseBuyStatement.setInt(2,204);
addUserCourseBuyStatement.setInt(3,277);
addUserCourseBuyStatement.setInt(4,180);
addUserCourseBuyStatement.setString(5,"批量赠送");
addUserCourseBuyStatement.execute();
}
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void userCourseBuyShopProductCourse() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
//1741 中医学课程三年VIP; 1743 中医学课程四年VIP;
//1737 肿瘤学课程三年vip; 1738 肿瘤学课程四年vip;
//1731 针灸学课程三年VIP 1732 针灸学课程四年VIP;
//1739 国学课程三年VIP; 1740 国学课程四年VIP;
//1735 心理学课程三年VIP 1736 心理学课程四年VIP;
// String productIdstr = "1741,1737,1731";
// String productIdstr = "1739,1735";
// String productIdstr = "1743,1738,1732";
// String productIdstr = "1740,1736";
String productIdstr = "1741";
String[] productIds = productIdstr.split(",");
for(String s:productIds){
int productId = Integer.parseInt(s); //商品id
String str = "15963311121";
String come = "开通";
int days = 0;//天数
PreparedStatement spStatement = fzdsconn.prepareStatement("" +
"select * from shop_product where product_id = "+productId+" and del_flag=0 ");
ResultSet spResultSet = spStatement.executeQuery();
while(spResultSet.next()){
come += spResultSet.getString("product_name");
if (come.contains("三年")){
days = 1095;
}else if (come.contains("四年")){
days = 1460;
}else if (come.contains("一年")){
days = 365;
}else {
System.out.println("商品年限有问题");
return;
}
}
if (days == 0) {
System.out.println("商品不存在");
return;
}
String[] tels = str.split(",");
int i=0;
for (String tel : tels) {
tel = tel.replace("\n","");
PreparedStatement addUserCourseBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_course_buy (user_id,course_id,catalogue_id,days,come) VALUES (?, ?, ?, ?, ?)");
PreparedStatement statement = fzdsconn.prepareStatement("select * from user where tel = '"+tel+"' and del_flag=0 ");
ResultSet resultSet = statement.executeQuery();
List<Object> list = new ArrayList<>();
while(resultSet.next()){
list.add(resultSet.getString("id"));
}
if (list.size() == 0){
System.out.println(tel+"-无账号");
}else if (list.size() > 1){
System.out.println(tel+"-多账号");
}else {
PreparedStatement spcStatement = fzdsconn.prepareStatement("" +
"select * from shop_product_course where product_id = "+productId+" and del_flag=0 ");
ResultSet spcResultSet = spcStatement.executeQuery();
while(spcResultSet.next()){
PreparedStatement ucbStatement = fzdsconn.prepareStatement("" +
"select * from user_course_buy where user_id = "+list.get(0).toString()+" " +
"and course_id = "+spcResultSet.getInt("course_id")+" " +
"and catalogue_id = "+spcResultSet.getInt("catalogue_id")+" and del_flag=0 ");
ResultSet ucbResultSet = ucbStatement.executeQuery();
while(ucbResultSet.next()){
PreparedStatement updateStatement = fzdsconn.prepareStatement(
"update user_course_buy set come='"+ucbResultSet.getString("come")+";"+come+"删除',del_flag = -1 " +
"where id = "+ucbResultSet.getInt("id"));
updateStatement.executeUpdate();
}
addUserCourseBuyStatement.setString(1,list.get(0).toString());
addUserCourseBuyStatement.setInt(2,spcResultSet.getInt("course_id"));
addUserCourseBuyStatement.setInt(3,spcResultSet.getInt("catalogue_id"));
addUserCourseBuyStatement.setInt(4,days);
addUserCourseBuyStatement.setString(5,come);
addUserCourseBuyStatement.addBatch();
}
i++;
System.out.println(productId+"-"+i+"-"+tel+"-已完成");
}
addUserCourseBuyStatement.executeBatch();
}
}
fzdsconn.close();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("完成!");
}
public static void userCourseBuyShopProductCourse22() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement addUserCourseBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_vip (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
PreparedStatement statement = fzdsconn.prepareStatement("select bo.create_time,bo.user_id,bop.product_id,sp.product_name from buy_order_product bop " +
"left join shop_product sp on sp.product_id = bop.product_id " +
"left join buy_order bo on bo.order_id = bop.order_id " +
"where bop.product_id in (1743,1740,1738,1736,1732) " +//,1743,1740,1738,1736,1732
"and bo.order_status = 3 " +
"order by product_name,user_id ");
ResultSet resultSet = statement.executeQuery();
while(resultSet.next()){
Date date = resultSet.getTimestamp("create_time");
Timestamp timestamp1 = new Timestamp(date.getTime());
Timestamp timestamp2 = new Timestamp(DateUtils.addYears(date,4).getTime());
addUserCourseBuyStatement.setInt(1,resultSet.getInt("user_id"));
if (resultSet.getInt("product_id")==1743){
addUserCourseBuyStatement.setInt(2,4);
}else if (resultSet.getInt("product_id")==1740){
addUserCourseBuyStatement.setInt(2,7);
}else if (resultSet.getInt("product_id")==1738){
addUserCourseBuyStatement.setInt(2,6);
}else if (resultSet.getInt("product_id")==1736){
addUserCourseBuyStatement.setInt(2,8);
}else if (resultSet.getInt("product_id")==1732){
addUserCourseBuyStatement.setInt(2,5);
}
addUserCourseBuyStatement.setTimestamp(3,timestamp1);
addUserCourseBuyStatement.setTimestamp(4,timestamp2);
addUserCourseBuyStatement.setInt(5,0);
addUserCourseBuyStatement.addBatch();
System.out.println(resultSet.getInt("user_id")+"-已完成");
}
addUserCourseBuyStatement.executeBatch();
System.out.println("-已完成");
fzdsconn.close();
}catch (SQLException e) {
}
}
public static void userCourseBuyOnload() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement addUserCourseBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_vip (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
PreparedStatement ucbStatement = fzdsconn.prepareStatement("" +
"select * from user_vip where type = 4 and state = 0 and del_flag = 0 ");
ResultSet ucbResultSet = ucbStatement.executeQuery();
int i=0;
while(ucbResultSet.next()){
i++;
addUserCourseBuyStatement.setInt(1,ucbResultSet.getInt("user_id"));
addUserCourseBuyStatement.setInt(2,9);
addUserCourseBuyStatement.setTimestamp(3,ucbResultSet.getTimestamp("start_time"));
addUserCourseBuyStatement.setTimestamp(4,ucbResultSet.getTimestamp("end_time"));
addUserCourseBuyStatement.setInt(5,0);
addUserCourseBuyStatement.addBatch();
System.out.println(ucbResultSet.getString("user_id")+"-已完成");
}
addUserCourseBuyStatement.executeBatch();
fzdsconn.close();
}catch (SQLException e) {
}
}
public static void userCourseBuyOnload2() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement addUserCourseBuyStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_course_buy (user_id,course_id,catalogue_id,create_time,days,come,start_time,end_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement ucbStatement = fzdsconn.prepareStatement("" +
"select * from user_course_buy where catalogue_id = 286 and del_flag = 0 ");
ResultSet ucbResultSet = ucbStatement.executeQuery();
int i=0;
while(ucbResultSet.next()){
i++;
addUserCourseBuyStatement.setInt(1,ucbResultSet.getInt("user_id"));
addUserCourseBuyStatement.setInt(2,214);
addUserCourseBuyStatement.setInt(3,293);
addUserCourseBuyStatement.setTimestamp(4,ucbResultSet.getTimestamp("create_time"));
addUserCourseBuyStatement.setInt(5,ucbResultSet.getInt("days"));
addUserCourseBuyStatement.setString(6,ucbResultSet.getString("come"));
addUserCourseBuyStatement.setTimestamp(7,ucbResultSet.getTimestamp("start_time"));
addUserCourseBuyStatement.setTimestamp(8,ucbResultSet.getTimestamp("end_time"));
addUserCourseBuyStatement.addBatch();
System.out.println(ucbResultSet.getString("user_id")+"-已完成");
}
addUserCourseBuyStatement.executeBatch();
fzdsconn.close();
}catch (SQLException e) {
}
}
public static void userVipUpdate() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
int x=0;
PreparedStatement addUserVipStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_vip (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
PreparedStatement uvStatement = fzdsconn.prepareStatement("" +
"select * from user_vip where type in (1,2,3) and del_flag=0 ");
ResultSet uvResultSet = uvStatement.executeQuery();
while(uvResultSet.next()){
x++;
if (uvResultSet.getInt("type")==1){
for (int i = 4; i < 9;i++) {
addUserVipStatement.setInt(1,uvResultSet.getInt("user_id"));
addUserVipStatement.setInt(2,i);
addUserVipStatement.setTimestamp(3,uvResultSet.getTimestamp("start_time"));
addUserVipStatement.setTimestamp(4,uvResultSet.getTimestamp("end_time"));
addUserVipStatement.setInt(5,uvResultSet.getInt("state"));
addUserVipStatement.addBatch();
}
}else if (uvResultSet.getInt("type")==2){
for (int i = 4; i < 7;i++) {
addUserVipStatement.setInt(1,uvResultSet.getInt("user_id"));
addUserVipStatement.setInt(2,i);
addUserVipStatement.setTimestamp(3,uvResultSet.getTimestamp("start_time"));
addUserVipStatement.setTimestamp(4,uvResultSet.getTimestamp("end_time"));
addUserVipStatement.setInt(5,uvResultSet.getInt("state"));
addUserVipStatement.addBatch();
}
}else if (uvResultSet.getInt("type")==3){
addUserVipStatement.setInt(1,uvResultSet.getInt("user_id"));
addUserVipStatement.setInt(2,7);
addUserVipStatement.setTimestamp(3,uvResultSet.getTimestamp("start_time"));
addUserVipStatement.setTimestamp(4,uvResultSet.getTimestamp("end_time"));
addUserVipStatement.setInt(5,uvResultSet.getInt("state"));
addUserVipStatement.addBatch();
}
PreparedStatement updateStatement = fzdsconn.prepareStatement(
"update user_vip set state = 1, del_flag = -1 " +
"where id = "+uvResultSet.getInt("id"));
updateStatement.executeUpdate();
System.out.println(x+"-已完成");
}
addUserVipStatement.executeBatch();
fzdsconn.close();
}catch (SQLException e) {
}
}
}