From 97f8e957001c8241f2be86c81bec116b7c4460f9 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Thu, 9 Oct 2025 16:18:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=866.30=E4=B9=8B=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E5=BC=80=E8=AF=BE=E8=AE=A2=E5=8D=95=E5=BD=95=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E5=BC=80=E8=AF=BE=E6=97=A5=E5=BF=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/UserCourseBuyUtil.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/main/java/com/peanut/common/utils/UserCourseBuyUtil.java b/src/main/java/com/peanut/common/utils/UserCourseBuyUtil.java index 79a792a9..3e33ef42 100644 --- a/src/main/java/com/peanut/common/utils/UserCourseBuyUtil.java +++ b/src/main/java/com/peanut/common/utils/UserCourseBuyUtil.java @@ -23,7 +23,77 @@ public class UserCourseBuyUtil { // userVipUpdate(); // distinctUserCourseBuy(); // addUserCourseBuyLog(); +// addUserCourseBuyLogSupplement(); } + + public static void addUserCourseBuyLogSupplement() { + 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 bo.create_time > '2025-06-30' + 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,'%') + + 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 bo.create_time > '2025-06-30' + 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,'%') + + order by orderSn + """); + ResultSet resultSet = statement.executeQuery(); + while(resultSet.next()){ + PreparedStatement logStatement = fzdsconn.prepareStatement("select * from user_course_buy_log where user_course_buy_id = "+resultSet.getString("id")); + ResultSet logResultSet = logStatement.executeQuery(); + boolean flag = true; + if(logResultSet.next()){ + flag = false; + } + if(flag){ + 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 addUserCourseBuyLog() { try { Connection fzdsconn = DriverManager.getConnection(