540 lines
32 KiB
Java
540 lines
32 KiB
Java
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();
|
|
// distinctUserCourseBuy();
|
|
// addUserCourseBuyLog();
|
|
}
|
|
public static void addUserCourseBuyLog() {
|
|
try {
|
|
Connection fzdsconn = DriverManager.getConnection(
|
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
|
"nuttyreading", "Wu751019!");
|
|
PreparedStatement addUserCourseBuyLogStatement = fzdsconn.prepareStatement(
|
|
"INSERT ignore INTO user_course_buy_log (user_course_buy_id,user_id,type,pay_type,pay_time,order_sn,days,fee) " +
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
|
PreparedStatement statement = fzdsconn.prepareStatement("""
|
|
select t.*,ucb.id,ROUND(orderPrice/t.productCount,2) price,ucb.days,ucb.come,ucb.start_time startTime,ucb.end_time endTime
|
|
from
|
|
(
|
|
select bo.order_sn orderSn,bo.create_time createTime,IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,sp.product_name title,
|
|
(select count(1) from shop_product_course where del_flag = 0 and product_id = bop.product_id) productCount,
|
|
bo.real_money orderPrice,bo.user_id userId,spc.course_id courseId,spc.catalogue_id catalogueId
|
|
from buy_order bo
|
|
left join buy_order_product bop on bop.order_id = bo.order_id
|
|
left join shop_product sp on sp.product_id = bop.product_id
|
|
left join shop_product_course spc on spc.product_id = sp.product_id
|
|
where bo.del_flag = 0 and bo.order_status = 3 and bo.order_type = 'order' and real_money > 0
|
|
and sp.goods_type = '05' and spc.del_flag = 0 and sp.product_id not in (1759,1758,1743,1741,1740,1739,1738,1737,1736,1735,1734,17331732,1731)
|
|
and bo.user_id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
|
|
) t
|
|
left join user_course_buy ucb on ucb.user_id = t.userId and ucb.course_id = t.courseId and ucb.catalogue_id = t.catalogueId and ucb.come like CONCAT('%',t.orderSn,'%')
|
|
where ucb.del_flag = 0
|
|
union
|
|
select t.*,ucb.id,t.orderPrice price,ucb.days,ucb.come,ucb.start_time startTime,ucb.end_time endTime
|
|
from
|
|
(
|
|
select bo.order_sn orderSn,bo.create_time createTime,IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,bo.remark title,1 productCount,bo.real_money orderPrice,bo.user_id userId,spc.course_id courseId,spc.catalogue_id catalogueId
|
|
from buy_order bo
|
|
left join shop_product sp on sp.product_id = SUBSTR(bo.remark FROM 1 FOR 4)
|
|
left join shop_product_course spc on spc.product_id = sp.product_id
|
|
where bo.del_flag = 0 and bo.order_status = 3 and bo.order_type = 'relearn' and real_money > 0
|
|
and sp.goods_type = '05' and spc.del_flag = 0 and sp.product_id not in (1759,1758,1743,1741,1740,1739,1738,1737,1736,1735,1734,17331732,1731)
|
|
and bo.user_id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
|
|
) t
|
|
left join user_course_buy ucb on ucb.user_id = t.userId and ucb.course_id = t.courseId and ucb.catalogue_id = t.catalogueId and ucb.come like CONCAT('%',t.orderSn,'%')
|
|
where ucb.del_flag = 0
|
|
order by orderSn
|
|
""");
|
|
ResultSet resultSet = statement.executeQuery();
|
|
while(resultSet.next()){
|
|
addUserCourseBuyLogStatement.setString(1,resultSet.getString("id"));
|
|
addUserCourseBuyLogStatement.setString(2,resultSet.getString("userId"));
|
|
addUserCourseBuyLogStatement.setString(3,"order");
|
|
addUserCourseBuyLogStatement.setString(4,resultSet.getString("payType"));
|
|
addUserCourseBuyLogStatement.setTimestamp(5,resultSet.getTimestamp("createTime"));
|
|
addUserCourseBuyLogStatement.setString(6,resultSet.getString("orderSn"));
|
|
addUserCourseBuyLogStatement.setString(7,resultSet.getString("days"));
|
|
addUserCourseBuyLogStatement.setString(8,resultSet.getString("price"));
|
|
addUserCourseBuyLogStatement.addBatch();
|
|
}
|
|
addUserCourseBuyLogStatement.executeBatch();
|
|
} catch (Exception e) {
|
|
System.out.println(e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void distinctUserCourseBuy() {
|
|
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 user_id,course_id,catalogue_id,count(1) c from user_course_buy where del_flag = 0
|
|
group by user_id,course_id,catalogue_id
|
|
HAVING c > 1
|
|
order by c desc
|
|
""");
|
|
ResultSet resultSet = statement.executeQuery();
|
|
while(resultSet.next()){
|
|
System.out.println(resultSet.getString("user_id"));
|
|
PreparedStatement ucbStatement = fzdsconn.prepareStatement("select * from user_course_buy where del_flag = 0 " +
|
|
"and user_id = "+resultSet.getString("user_id")+" " +
|
|
"and course_id = "+resultSet.getString("course_id")+" " +
|
|
"and catalogue_id = "+resultSet.getString("catalogue_id")+"");
|
|
ResultSet ucbResultSet = ucbStatement.executeQuery();
|
|
int i=0;
|
|
while(ucbResultSet.next()){
|
|
if(i!=0){
|
|
PreparedStatement delStatement = fzdsconn.prepareStatement(
|
|
"update user_course_buy set del_flag = -1 where id = "+ucbResultSet.getString("id"));
|
|
delStatement.executeUpdate();
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println(e);
|
|
}
|
|
|
|
}
|
|
|
|
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!");
|
|
PreparedStatement statement = fzdsconn.prepareStatement("" +
|
|
"select user_id from user_course_buy where del_flag = 0 and (course_id = 324 or course_id = 217) and user_id not in (select user_id from user_vip where type = 8 and state = 0 and del_flag = 0 ) group by user_id");
|
|
ResultSet resultSet = statement.executeQuery();
|
|
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 (?, ?, ?, ?, ?, ?, ?, ?)");
|
|
while(resultSet.next()){
|
|
PreparedStatement statement324 = fzdsconn.prepareStatement("" +
|
|
"select * from user_course_buy where del_flag = 0 and (course_id = 324 or course_id = 217) " +
|
|
"and user_id = "+resultSet.getInt("user_id")+" order by end_time desc");
|
|
ResultSet resultSet324 = statement324.executeQuery();
|
|
while(resultSet324.next()){
|
|
for (int i=325;i<331;i++){
|
|
addUserCourseBuyStatement.setInt(1,resultSet324.getInt("user_id"));
|
|
addUserCourseBuyStatement.setInt(2,i);
|
|
if (i==325){
|
|
addUserCourseBuyStatement.setInt(3,357);
|
|
}else if (i==326){
|
|
addUserCourseBuyStatement.setInt(3,358);
|
|
}else if (i==327){
|
|
addUserCourseBuyStatement.setInt(3,360);
|
|
}else if (i==328){
|
|
addUserCourseBuyStatement.setInt(3,361);
|
|
}else if (i==329){
|
|
addUserCourseBuyStatement.setInt(3,362);
|
|
}else{
|
|
addUserCourseBuyStatement.setInt(3,363);
|
|
}
|
|
addUserCourseBuyStatement.setTimestamp(4,resultSet324.getTimestamp("create_time"));
|
|
addUserCourseBuyStatement.setInt(5,resultSet324.getInt("days"));
|
|
addUserCourseBuyStatement.setString(6,resultSet324.getString("come"));
|
|
addUserCourseBuyStatement.setTimestamp(7,resultSet324.getTimestamp("start_time"));
|
|
addUserCourseBuyStatement.setTimestamp(8,resultSet324.getTimestamp("end_time"));
|
|
addUserCourseBuyStatement.addBatch();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
addUserCourseBuyStatement.executeBatch();
|
|
} 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) {
|
|
|
|
}
|
|
}
|
|
|
|
}
|