数据合并

湖分兑换剩余
This commit is contained in:
wuchunlei
2024-05-27 14:52:34 +08:00
parent 954513ab6d
commit 05c2ac661d
6 changed files with 286 additions and 48 deletions

View File

@@ -29,9 +29,10 @@ public class DataMigrationUtil extends Thread {
public static void main(String[] args){
// catalogue();
// courseCatalogue();
// userCourse();
// courseCatalogueChapter();
// courseCatalogueChapterVideo();
user();//用的都是copy表里的数据
//用的都是copy表里的数据
// truncate();
}
@@ -41,9 +42,11 @@ public class DataMigrationUtil extends Thread {
Connection yljkconn = DriverManager.getConnection(
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
PreparedStatement statement = yljkconn.prepareStatement("select * from t_curriculum_catalogue where valid = 1" +
" and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid is null) " +
"and (courseFee like '%,%' or courseFee = '0' or courseFee = '' or poid = '00000000000000000000000000000070' )");
// PreparedStatement statement = yljkconn.prepareStatement("select * from t_curriculum_catalogue where valid = 1" +
// " and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid is null) " +
// "and (courseFee like '%,%' or courseFee = '0' or courseFee = '' or poid = '00000000000000000000000000000070' )");
PreparedStatement statement = yljkconn.prepareStatement("select * from t_curriculum_catalogue " +
"where oid = 'ee9d5e16845a43b5933ecc111ee52052' ");
ResultSet resultSet = statement.executeQuery();
List<Map> list = new ArrayList();
while(resultSet.next()){
@@ -61,13 +64,13 @@ public class DataMigrationUtil extends Thread {
statement.close();
Connection connection = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// 关闭自动提交事务,改为手动提交
connection.setAutoCommit(false);
System.out.println("===== 开始插入数据 =====");
long startTime = System.currentTimeMillis();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT ignore INTO course_copy1 (uid,title,sort,image,content,create_time) VALUES ( ?, ?, ?, ?, ?, ?)");
PreparedStatement preparedStatement = connection.prepareStatement("INSERT ignore INTO course (uid,title,sort,image,content,create_time) VALUES ( ?, ?, ?, ?, ?, ?)");
for (int i = 0; i < list.size(); i++) {
preparedStatement.setString(1,list.get(i).get("oid").toString());
preparedStatement.setString(2,list.get(i).get("title").toString());
@@ -104,9 +107,10 @@ public class DataMigrationUtil extends Thread {
public static void courseCatalogue(){
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement fzdsstatement = fzdsconn.prepareStatement("select id,uid from course ");
// PreparedStatement fzdsstatement = fzdsconn.prepareStatement("select id,uid from course ");
PreparedStatement fzdsstatement = fzdsconn.prepareStatement("select id,uid from course where id = 183 ");
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
List<Map> fzdslist = new ArrayList();
while(fzdsresultSet.next()){
@@ -122,7 +126,7 @@ public class DataMigrationUtil extends Thread {
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// 关闭自动提交事务,改为手动提交
connection.setAutoCommit(false);
@@ -188,13 +192,77 @@ public class DataMigrationUtil extends Thread {
}
}
public static void userCourse(){
try {
Connection yljkconn = DriverManager.getConnection(
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// 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();
// while(resultSet.next()){
// PreparedStatement fzdsstatement = connection.prepareStatement("select * from user where yljk_oid = '"+resultSet.getString("oid")+"'");
// ResultSet fzdsresultSet = fzdsstatement.executeQuery();
// if (!fzdsresultSet.next()){
// user(yljkconn,connection,resultSet.getString("oid"));
// }
// }
List list = new ArrayList();
list.add("137a4c15dad741f1b8bdcf3f1ed29bb2");
list.add("4f50a94045994dafb16c337f9b590d3d");
for (int i=0;i<list.size(); i++){
user(yljkconn,connection,list.get(i).toString());
}
System.out.println("完成---");
} catch (SQLException e) {
System.out.println("Error: " + e.getMessage());
}
}
public static void userCourseBuy(){
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!");
PreparedStatement statement = yljkconn.prepareStatement("select oid,superVIP,paydate,payValidDate " +
"from t_customer where valid = 1 and cellphone != '' and cellphone is not null " +
"and superVIP in ('1','2')");
ResultSet resultSet = statement.executeQuery();
int k=0;
while(resultSet.next()){
k++;
System.out.println(k);
// PreparedStatement fzdsstatement = fzdsconn.prepareStatement("select * from user where yljk_oid = '"+resultSet.getString("oid")+"'");
// ResultSet fzdsresultSet = fzdsstatement.executeQuery();
// if (fzdsresultSet.next()){
// String sql = "update user set " +
// "vip= '"+resultSet.getString("superVIP")+"' " +
// "where yljk_oid = "+resultSet.getString("oid")+"";
// PreparedStatement oidUpdateStatement = fzdsconn.prepareStatement(sql);
// oidUpdateStatement.execute();
//
// }
}
} catch (SQLException e) {
System.out.println("Error: " + e.getMessage());
}
}
public static void courseCatalogueChapter(){
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// PreparedStatement fzdsstatement = fzdsconn.prepareStatement(
// "select c.id,c.uid,cc.id ccid,cc.title cctitle from course c left join course_catalogue cc on c.id = cc.course_id ");
PreparedStatement fzdsstatement = fzdsconn.prepareStatement(
"select c.id,c.uid,cc.id ccid,cc.title cctitle from course c left join course_catalogue cc on c.id = cc.course_id ");
"select c.id,c.uid,cc.id ccid,cc.title cctitle from course c left join course_catalogue cc on c.id = cc.course_id " +
"where c.id = 183");
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
List<Map> fzdslist = new ArrayList();
while(fzdsresultSet.next()){
@@ -209,7 +277,7 @@ public class DataMigrationUtil extends Thread {
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
long startTime = System.currentTimeMillis();
System.out.println("===== 开始插入数据 =====");
@@ -261,10 +329,13 @@ public class DataMigrationUtil extends Thread {
public static void courseCatalogueChapterVideo(){
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// PreparedStatement fzdsstatement = fzdsconn.prepareStatement(
// "select c.uid,ccc.id as cccid,ccc.title from course c left join course_catalogue_chapter ccc on c.id = ccc.course_id");
PreparedStatement fzdsstatement = fzdsconn.prepareStatement(
"select c.uid,ccc.id as cccid,ccc.title from course c left join course_catalogue_chapter ccc on c.id = ccc.course_id");
"select c.uid,ccc.id as cccid,ccc.title from course c left join course_catalogue_chapter ccc on c.id = ccc.course_id " +
"where c.id = 183");
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
List<Map> fzdslist = new ArrayList();
while(fzdsresultSet.next()){
@@ -278,7 +349,7 @@ public class DataMigrationUtil extends Thread {
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
long startTime = System.currentTimeMillis();
System.out.println("===== 开始插入数据 =====");
@@ -358,14 +429,18 @@ public class DataMigrationUtil extends Thread {
}
}
public static void user(){
truncate();
public static void user(Connection yljkconn, Connection fzdsconn,String oid){
// truncate();
try {
long startTime = System.currentTimeMillis();
Connection yljkconn = DriverManager.getConnection(
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
"yljkmaster", "Wu751019!@");
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 ");
// Connection yljkconn = DriverManager.getConnection(
// "jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
// "yljkmaster", "Wu751019!@");
// 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 ");
PreparedStatement statement = yljkconn.prepareStatement("select oid,cellPhone,nameCN,nickName,icons,superVIP," +
"point,pointByJF,payStatus,paydate,payValidDate from t_customer where oid = '"+oid+"' ");
ResultSet resultSet = statement.executeQuery();
List<Map> list = new ArrayList();
while(resultSet.next()){
@@ -384,16 +459,15 @@ public class DataMigrationUtil extends Thread {
list.add(map);
}
resultSet.close();
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
// Connection fzdsconn = DriverManager.getConnection(
// "jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book?rewriteBatchedStatements=true",
// "nuttyreading", "Wu751019!");
// 1、创建服务创建线程池
ExecutorService service = Executors.newFixedThreadPool(50);
ExecutorService service = Executors.newFixedThreadPool(1);
for (int i=0;i<list.size(); i++){
DataMigrationUtil d1 = new DataMigrationUtil(list.get(i),i+1,yljkconn,fzdsconn);
service.execute(d1);
}
System.out.println("---开始");
} catch (SQLException e) {
System.out.println("Error: " + e.getMessage());
}
@@ -402,19 +476,16 @@ public class DataMigrationUtil extends Thread {
@Override
public void run(){
try {
if (i % 1000 == 0) {
System.out.println("---已插入数据"+i+"--"+ DateUtil.format(new Date(),"YYYY-MM-dd HH:mm:ss"));
}
String userId = "";
BigDecimal userBalanceCoin = new BigDecimal(0);
BigDecimal userBalanceJf = new BigDecimal(0);
PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and yljk_oid = '"+map.get("oid")+"' ");
PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user where del_flag = 0 and yljk_oid = '"+map.get("oid")+"' ");
ResultSet oidResultSet = oidStatements.executeQuery();
//已绑定过id
if (oidResultSet.next()){
userBalanceCoin = oidResultSet.getBigDecimal("peanut_coin").add(new BigDecimal(map.get("point").toString()));
userBalanceJf = oidResultSet.getBigDecimal("jf").add(new BigDecimal(map.get("pointByJF").toString()));
String sql = "update user_copy1 set " +
String sql = "update user set " +
"name = if(isnull(name),'"+map.get("nameCN")+"',name) , nickname = if(isnull(nickname),'"+map.get("nickName")+"',nickname) ," +
"tel = if(isnull(tel),'"+map.get("cellPhone")+"',tel) ," +
"vip= "+map.get("payStatus")+" ,peanut_coin = peanut_coin + "+map.get("point")+" , jf = jf + "+map.get("pointByJF")+" where id = "+oidResultSet.getString("id")+"";
@@ -424,7 +495,7 @@ public class DataMigrationUtil extends Thread {
oidUpdateStatement.close();
}else {
//未绑定过id用电话查询
PreparedStatement telStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and tel = '"+map.get("cellPhone")+"' ");
PreparedStatement telStatements = fzdsconn.prepareStatement("select * from user where del_flag = 0 and tel = '"+map.get("cellPhone")+"' ");
ResultSet telResultSet = telStatements.executeQuery();
if (telResultSet.next()){
if (telResultSet.getRow()>1){//这里需要检查
@@ -432,7 +503,7 @@ public class DataMigrationUtil extends Thread {
}else {
userBalanceCoin = telResultSet.getBigDecimal("peanut_coin").add(new BigDecimal(map.get("point").toString()));
userBalanceJf = telResultSet.getBigDecimal("jf").add(new BigDecimal(map.get("pointByJF").toString()));
String sql = "update user_copy1 set yljk_oid = '" + map.get("oid") +"',"+
String sql = "update user set yljk_oid = '" + map.get("oid") +"',"+
" name = if(isnull(name),'"+map.get("nameCN")+"',name) , nickname = if(isnull(nickname),'"+map.get("nickName")+"',nickname) ," +
"vip= "+map.get("payStatus")+" ,peanut_coin = peanut_coin + "+map.get("point")+" , jf = jf + "+map.get("pointByJF")+" where tel = '"+map.get("cellPhone")+"'";
PreparedStatement telUpdateStatement = fzdsconn.prepareStatement(sql);
@@ -443,15 +514,15 @@ public class DataMigrationUtil extends Thread {
}else {
//没有关联,直接导入
PreparedStatement telInsertStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_copy1 (name,avatar,nickname,tel,vip,peanut_coin,jf,yljk_oid) " +
"INSERT INTO user (name,avatar,nickname,tel,vip,peanut_coin,jf,yljk_oid) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)",PreparedStatement.RETURN_GENERATED_KEYS);
telInsertStatement.setString(1,map.get("nameCN")==null?"":map.get("nameCN").toString());
telInsertStatement.setString(2,map.get("icons")==null?"":map.get("icons").toString());
telInsertStatement.setString(3,map.get("nickName")==null?"":map.get("nickName").toString());
telInsertStatement.setString(4,map.get("cellPhone")==null?"":map.get("cellPhone").toString());
telInsertStatement.setString(5,map.get("payStatus")==null?"":map.get("payStatus").toString());
telInsertStatement.setString(6,map.get("point")==null?"":map.get("point").toString());
telInsertStatement.setString(7,map.get("pointByJF")==null?"":map.get("pointByJF").toString());
telInsertStatement.setString(5,map.get("superVIP")==null?"":map.get("superVIP").toString());
telInsertStatement.setBigDecimal(6,new BigDecimal(map.get("point").toString()));
telInsertStatement.setBigDecimal(7,new BigDecimal(map.get("pointByJF").toString()));
telInsertStatement.setString(8,map.get("oid")==null?"":map.get("oid").toString());
telInsertStatement.execute();//获取添加之后自动增长id值
ResultSet rs = telInsertStatement.getGeneratedKeys();
@@ -464,10 +535,10 @@ public class DataMigrationUtil extends Thread {
userBalanceJf = new BigDecimal(map.get("pointByJF").toString());
}
}
//添加超v
if (map.get("paydate")!=null&&map.get("payValidDate")!=null){
//添加超v
PreparedStatement userVipStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_vip_copy1 (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
"INSERT ignore INTO user_vip (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
userVipStatement.setString(1,userId);
userVipStatement.setString(2,map.get("payStatus").toString());
userVipStatement.setString(3,map.get("paydate").toString());
@@ -483,7 +554,7 @@ public class DataMigrationUtil extends Thread {
if (map.get("point")!=null&&!"0".equals(map.get("point").toString())){
//添加虚拟币记录
PreparedStatement transactionDetailStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO transaction_details_copy1 (user_id,order_type,change_amount,remark,user_balance," +
"INSERT ignore INTO transaction_details (user_id,order_type,change_amount,remark,user_balance," +
"user_name,tel) VALUES (?, ?, ?, ?, ?, ?, ?)");
transactionDetailStatement.setString(1,userId);
transactionDetailStatement.setString(2,"系统合并结算");
@@ -498,7 +569,7 @@ public class DataMigrationUtil extends Thread {
if (map.get("pointByJF")!=null&&!"0".equals(map.get("pointByJF").toString())){
//添加积分记录
PreparedStatement jfTransactionDetailStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO jf_transaction_details_copy1 (user_id,act_type,change_amount,user_balance,remark) " +
"INSERT ignore INTO jf_transaction_details (user_id,act_type,change_amount,user_balance,remark) " +
"VALUES (?, ?, ?, ?, ?)");
jfTransactionDetailStatement.setString(1,userId);
jfTransactionDetailStatement.setString(2,"0");
@@ -513,11 +584,11 @@ public class DataMigrationUtil extends Thread {
PreparedStatement contributionStatements = yljkconn.prepareStatement("" +
"select * from t_customer_contribution where valid = 1 and customerOid = '"+map.get("oid")+"' ");
ResultSet contributionResultSet = contributionStatements.executeQuery();
if (contributionResultSet.next()){
//添加湖分记录
PreparedStatement contributionStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_contribution (user_id,score,detail,type,conversion_flag,create_time) " +
"VALUES (?, ?, ?, ?, ?, ?)");
//添加湖分记录
PreparedStatement contributionStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_contribution (user_id,score,detail,type,conversion_flag,create_time) " +
"VALUES (?, ?, ?, ?, ?, ?)");
while(contributionResultSet.next()){
contributionStatement.setString(1,userId);
contributionStatement.setDouble(2,contributionResultSet.getDouble("score"));
contributionStatement.setString(3,contributionResultSet.getString("detail"));
@@ -525,9 +596,9 @@ public class DataMigrationUtil extends Thread {
contributionStatement.setInt(5,contributionResultSet.getInt("conversionFlg"));
contributionStatement.setTimestamp(6,contributionResultSet.getTimestamp("createDate"));
contributionStatement.execute();
contributionStatement.close();
}
contributionStatement.close();
System.out.println(map.get("oid"));
}catch (Exception ee){
System.out.println(map.get("nameCN")+"--"+ee.getMessage());
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.UserContributionExchange;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserContributionExchangeDao extends MPJBaseMapper<UserContributionExchange> {
}

View File

@@ -0,0 +1,30 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@Data
@TableName("user_contribution_exchange")
public class UserContributionExchange {
@TableId
private Integer id;
private Integer userId;
//剩余未换分数
private Double surplus;
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private MyUserEntity user;
}

View File

@@ -0,0 +1,34 @@
package com.peanut.modules.master.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.master.service.UserMergeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 合并用户
*/
@Slf4j
@RestController("masterUserMerge")
@RequestMapping("master/userMerge")
public class UserMergeController {
@Autowired
private UserMergeService mergeService;
@RequestMapping("/userMerge")
public R userMerge(@RequestBody Map<String, Object> params) {
mergeService.userMerge(params);
return null;
}
}

View File

@@ -0,0 +1,11 @@
package com.peanut.modules.master.service;
import com.peanut.common.utils.R;
import java.util.Map;
public interface UserMergeService {
R userMerge(Map<String, Object> params);
}

View File

@@ -0,0 +1,83 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.MyUserDao;
import com.peanut.modules.common.dao.UserContributionDao;
import com.peanut.modules.common.dao.UserContributionExchangeDao;
import com.peanut.modules.common.dao.UserCourseBuyDao;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserContribution;
import com.peanut.modules.common.entity.UserContributionExchange;
import com.peanut.modules.common.entity.UserCourseBuyEntity;
import com.peanut.modules.master.service.UserMergeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Slf4j
@Service("masterUserMergeService")
public class UserMergeServiceImpl implements UserMergeService {
@Autowired
private MyUserDao userDao;
@Autowired
private UserContributionDao contributionDao;
@Autowired
private UserContributionExchangeDao exchangeDao;
@Autowired
private UserCourseBuyDao courseBuyDao;
@Override
public R userMerge(Map<String, Object> params) {
MyUserEntity mainUser = userDao.selectById(params.get("mainAccountId").toString());
MyUserEntity secondUser = userDao.selectById(params.get("secondAccountId").toString());
if (mainUser != null){
if (secondUser!=null){
//虚拟币、积分
mainUser.setPeanutCoin(mainUser.getPeanutCoin().add(secondUser.getPeanutCoin()));
mainUser.setJf(mainUser.getJf().add(secondUser.getJf()));
userDao.updateById(mainUser);
//湖分
LambdaQueryWrapper<UserContribution> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UserContribution :: getUserId,secondUser.getId());
List<UserContribution> contributions = contributionDao.selectList(queryWrapper);
if (contributions != null&&contributions.size()>0) {
for (UserContribution c : contributions) {
c.setUserId(mainUser.getId());
contributionDao.updateById(c);
}
}
LambdaQueryWrapper<UserContributionExchange> exchangeWrapper = new LambdaQueryWrapper<>();
exchangeWrapper.eq(UserContributionExchange :: getUserId,secondUser.getId());
List<UserContributionExchange> exchanges = exchangeDao.selectList(exchangeWrapper);
if (exchanges != null&&exchanges.size()>0) {
for (UserContributionExchange c : exchanges) {
c.setUserId(mainUser.getId());
exchangeDao.updateById(c);
}
}
//课
LambdaQueryWrapper<UserCourseBuyEntity> courseWrapper = new LambdaQueryWrapper<>();
courseWrapper.eq(UserCourseBuyEntity :: getUserId,secondUser.getId());
List<UserCourseBuyEntity> courseBuys = courseBuyDao.selectList(courseWrapper);
if (courseBuys != null&&courseBuys.size()>0) {
for (UserCourseBuyEntity c : courseBuys) {
c.setUserId(mainUser.getId());
courseBuyDao.updateById(c);
}
}
//删除次用户
userDao.deleteById(secondUser.getId());
}else {
return R.error("次账号未找到");
}
}else {
return R.error("主账号未找到");
}
return null;
}
}