vip会员拆分明细工具

This commit is contained in:
wuchunlei
2025-09-16 14:07:11 +08:00
parent c2b536336a
commit 0366a9ea45

View File

@@ -3,20 +3,135 @@ package com.peanut.common.utils;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang.time.DateUtils;
import java.math.BigDecimal;
import java.sql.*;
import java.util.ArrayList;
import java.util.*;
import java.util.Date;
import java.util.List;
public class DataTest {
public static void main(String[] args){
// userVip();
// userVipDynamic();
// userCourseBuy1();
// addImageToCourse();
userVipLog();
}
public static void userVipLog(){
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement listStatement = fzdsconn.prepareStatement("""
select order_sn orderSn,bo.order_id,bo.create_time createTime,u.id,u.name,u.tel,u.email,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,bo.real_money money,
bo.jf_deduction jf,vbc.title,vbc.year year
from buy_order bo
left join user u on u.id = bo.user_id
left join vip_buy_config vbc on vbc.id = bo.vip_buy_config_id
where bo.del_flag = 0 and order_type = 'vip' and order_status = 3 and order_id > 17636
and 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'))
union
select order_sn orderSn,bo.order_id,bo.create_time createTime,u.id,u.name,u.tel,u.email,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,bo.real_money money,
bo.jf_deduction jf,sp.product_name title,IF(sp.product_name like '%三年%',3,4) year
from buy_order bo
left join user u on u.id = bo.user_id
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
where bo.del_flag = 0 and order_type = 'order' and order_status = 3 and sp.product_id in (1743,1741,1740,1739,1738,1737,1736,1735,1734,1733,1732,1731)
and 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'))
""");
PreparedStatement addUserVipLogStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_vip_log (user_id,user_vip_id,type,order_sn,start_time,end_time,fee,jf,day_amount,pay_type)" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ResultSet listResultSet = listStatement.executeQuery();
while (listResultSet.next()){
String userId = listResultSet.getString("id");
System.out.println(userId+"开始");
String title = listResultSet.getString("title");
Map map = new HashMap();
map.put("userId",userId);
map.put("orderSn",listResultSet.getString("orderSn"));
map.put("fee",listResultSet.getString("money"));
map.put("jf",listResultSet.getString("jf"));
map.put("payType",listResultSet.getString("payType"));
if ("医学超级VIP".equals(title)){
map.put("fee",listResultSet.getBigDecimal("money").divide(new BigDecimal("4"),2,BigDecimal.ROUND_HALF_UP)+"");
queryUserVip(4,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
queryUserVip(5,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
queryUserVip(6,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
queryUserVip(9,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("中医学VIP".equals(title)||title.contains("中医学课程")){
if (listResultSet.getTimestamp("createTime").getTime()<
com.peanut.common.utils.DateUtils.stringToDate("2025-03-12","yyyy-MM-dd").getTime()){
map.put("fee",listResultSet.getBigDecimal("money").divide(new BigDecimal("2"),2,BigDecimal.ROUND_HALF_UP)+"");
queryUserVip(9,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
queryUserVip(4,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("针灸学VIP".equals(title)||title.contains("针灸学课程")){
queryUserVip(5,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("肿瘤学VIP".equals(title)||title.contains("肿瘤学课程")){
queryUserVip(6,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("中西汇通学VIP".equals(title)){
queryUserVip(9,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("国学与心理学超级VIP".equals(title)){
map.put("fee",listResultSet.getBigDecimal("money").divide(new BigDecimal("2"),2,BigDecimal.ROUND_HALF_UP)+"");
queryUserVip(7,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
queryUserVip(8,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("众妙之门国学VIP".equals(title)||title.contains("国学课程")){
queryUserVip(7,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
if ("心理学VIP".equals(title)||title.contains("心理学课程")){
queryUserVip(8,fzdsconn,userId,map,listResultSet,addUserVipLogStatement);
}
}
addUserVipLogStatement.executeBatch();
} catch (SQLException e) {
System.out.println("Error: " + e.getMessage());
}
}
public static void queryUserVip(int type,Connection fzdsconn,String userId,Map map,ResultSet listResultSet,PreparedStatement addUserVipLogStatement) throws SQLException {
PreparedStatement userVipStatement = fzdsconn.prepareStatement("" +
"select * from user_vip where del_flag = 0 and type = "+type+" and state = 0 and user_id = "+userId);
ResultSet userVipResultSet = userVipStatement.executeQuery();
while (userVipResultSet.next()){
map.put("id",userVipResultSet.getString("id"));
map.put("startTime",userVipResultSet.getString("start_time"));
String d = com.peanut.common.utils.DateUtils.format(com.peanut.common.utils.DateUtils.addDateYears(
userVipResultSet.getTimestamp("start_time"),
listResultSet.getInt("year")),"yyyy-MM-dd HH:mm:ss");
map.put("endTime", d);
BigDecimal days = new BigDecimal((com.peanut.common.utils.DateUtils.addDateYears(
userVipResultSet.getTimestamp("start_time"),listResultSet.getInt("year")).getTime()
-userVipResultSet.getTimestamp("start_time").getTime())/24/60/60/1000);
map.put("dayAmount", new BigDecimal(map.get("fee").toString()).divide(days, 2, BigDecimal.ROUND_HALF_UP)+"");
addUserVipLog(addUserVipLogStatement,map);
}
}
public static void addUserVipLog(PreparedStatement addUserVipLogStatement, Map<String,String> map) throws SQLException {
// "INSERT ignore INTO user_vip_log (user_id,user_vip_id,type,order_sn,start_time,end_time,fee,jf,pay_type)"
addUserVipLogStatement.setString(1, map.get("userId"));
addUserVipLogStatement.setString(2, map.get("id"));
addUserVipLogStatement.setString(3, "order");
addUserVipLogStatement.setString(4, map.get("orderSn"));
addUserVipLogStatement.setString(5, map.get("startTime"));
addUserVipLogStatement.setString(6, map.get("endTime"));
addUserVipLogStatement.setString(7, map.get("fee"));
addUserVipLogStatement.setString(8, map.get("jf"));
addUserVipLogStatement.setString(9, map.get("dayAmount"));
addUserVipLogStatement.setString(10, map.get("payType"));
addUserVipLogStatement.addBatch();
}
public static void addImageToCourse(){
try {