Merge remote-tracking branch 'origin/zcc'
This commit is contained in:
384
src/main/java/com/peanut/common/utils/DataMigrationUtil.java
Normal file
384
src/main/java/com/peanut/common/utils/DataMigrationUtil.java
Normal file
@@ -0,0 +1,384 @@
|
|||||||
|
package com.peanut.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import org.apache.commons.lang.time.DateUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DataMigrationUtil {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
// catalogue();
|
||||||
|
// courseCatalogue();
|
||||||
|
// courseCatalogueChapter();
|
||||||
|
// courseCatalogueChapterVideo();
|
||||||
|
user();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void catalogue(){
|
||||||
|
try {
|
||||||
|
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 '%,%' ");
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
List<Map> list = new ArrayList();
|
||||||
|
while(resultSet.next()){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("oid",resultSet.getString("oid"));
|
||||||
|
map.put("title",resultSet.getString("title"));
|
||||||
|
map.put("createDate",resultSet.getString("createDate"));
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
yljkconn.close();
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
Connection connection = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
// 关闭自动提交事务,改为手动提交
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
System.out.println("===== 开始插入数据 =====");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("INSERT ignore INTO course (uid,title,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());
|
||||||
|
preparedStatement.setString(3,list.get(i).get("createDate").toString());
|
||||||
|
// 添加到批处理中
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
if (i+1 % 5000 == 0) {
|
||||||
|
long startTime1 = System.currentTimeMillis();
|
||||||
|
// 每1000条数据提交一次
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
long spendTime1 = System.currentTimeMillis()-startTime1;
|
||||||
|
System.out.println("成功插入第 "+ i+1+" 条数据,耗时:"+spendTime1+"毫秒");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 处理剩余的数据
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
connection.setAutoCommit(true);//在把自动提交打开
|
||||||
|
long spendTime = System.currentTimeMillis()-startTime;
|
||||||
|
System.out.println("成功插入"+list.size()+"条数据,耗时:"+spendTime+"毫秒");
|
||||||
|
connection.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void courseCatalogue(){
|
||||||
|
try {
|
||||||
|
Connection fzdsconn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
PreparedStatement fzdsstatement = fzdsconn.prepareStatement("select id,uid from course ");
|
||||||
|
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
|
||||||
|
List<Map> fzdslist = new ArrayList();
|
||||||
|
while(fzdsresultSet.next()){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("id",fzdsresultSet.getString("id"));
|
||||||
|
map.put("uid",fzdsresultSet.getString("uid"));
|
||||||
|
fzdslist.add(map);
|
||||||
|
}
|
||||||
|
fzdsresultSet.close();
|
||||||
|
fzdsconn.close();
|
||||||
|
fzdsstatement.close();
|
||||||
|
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_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
// 关闭自动提交事务,改为手动提交
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
System.out.println("===== 开始插入数据 =====");
|
||||||
|
int res = 0;
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(
|
||||||
|
"INSERT ignore INTO course_catalogue (course_id,title,half_fee,fee,create_time) VALUES (?,?,?,?,?)");
|
||||||
|
for (int q=1;q<=fzdslist.size(); q++){
|
||||||
|
String selectSql = "select * from t_curriculum_catalogue where valid = 1 and poid = '"+fzdslist.get(q-1).get("uid")+"'";
|
||||||
|
PreparedStatement statement = yljkconn.prepareStatement(selectSql);
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
Map map = new HashMap();
|
||||||
|
while(resultSet.next()){
|
||||||
|
map.put("title",resultSet.getString("title"));
|
||||||
|
map.put("halfFee",resultSet.getString("courseFee").split(",")[0]);
|
||||||
|
map.put("fee",resultSet.getString("courseFee").split(",")[1]);
|
||||||
|
map.put("createDate",resultSet.getString("createDate"));
|
||||||
|
if (map.size() > 0){
|
||||||
|
preparedStatement.setString(1,fzdslist.get(q-1).get("id").toString());
|
||||||
|
preparedStatement.setString(2,map.get("title").toString());
|
||||||
|
preparedStatement.setString(3,map.get("halfFee").toString());
|
||||||
|
preparedStatement.setString(4,map.get("fee").toString());
|
||||||
|
preparedStatement.setString(5,map.get("createDate").toString());
|
||||||
|
// 添加到批处理中
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
res++;
|
||||||
|
if (res % 5000 == 0) {
|
||||||
|
long startTime1 = System.currentTimeMillis();
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
long spendTime1 = System.currentTimeMillis()-startTime1;
|
||||||
|
System.out.println("成功插入第"+ res +" 条数据,耗时:"+spendTime1+"毫秒");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
//处理剩余的数据
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
preparedStatement.close();
|
||||||
|
yljkconn.close();
|
||||||
|
connection.setAutoCommit(true);//在把自动提交打开
|
||||||
|
connection.close();
|
||||||
|
long spendTime = System.currentTimeMillis()-startTime;
|
||||||
|
System.out.println("成功插入"+res+"条数据,耗时:"+spendTime+"毫秒");
|
||||||
|
} 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",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
PreparedStatement fzdsstatement = fzdsconn.prepareStatement(
|
||||||
|
"select c.id,c.uid,cc.id as ccid from course c left join course_catalogue cc on c.id = cc.course_id ");
|
||||||
|
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
|
||||||
|
List<Map> fzdslist = new ArrayList();
|
||||||
|
while(fzdsresultSet.next()){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("id",fzdsresultSet.getString("id"));
|
||||||
|
map.put("uid",fzdsresultSet.getString("uid"));
|
||||||
|
map.put("ccid",fzdsresultSet.getString("ccid"));
|
||||||
|
fzdslist.add(map);
|
||||||
|
}
|
||||||
|
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_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
System.out.println("===== 开始插入数据 =====");
|
||||||
|
int res = 0;
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(
|
||||||
|
"INSERT ignore INTO course_catalogue_chapter (course_id,catalogue_id,title,img_url,content,create_time,sort) VALUES ( ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
for (int q=1;q<=fzdslist.size(); q++){
|
||||||
|
String selectSql = "select * from t_curriculum_detail where valid = 1 and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid = '"+fzdslist.get(q-1).get("uid")+"')";
|
||||||
|
PreparedStatement statement = yljkconn.prepareStatement(selectSql);
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
Map map = new HashMap();
|
||||||
|
while(resultSet.next()){
|
||||||
|
map.put("title",resultSet.getString("title"));
|
||||||
|
map.put("imgUrl",resultSet.getString("imgUrl"));
|
||||||
|
map.put("content",resultSet.getString("explains"));
|
||||||
|
map.put("createDate",resultSet.getString("createDate"));
|
||||||
|
map.put("sort",resultSet.getString("orderNo"));
|
||||||
|
if (map.size() > 0){
|
||||||
|
preparedStatement.setString(1,fzdslist.get(q-1).get("id").toString());
|
||||||
|
preparedStatement.setString(2,fzdslist.get(q-1).get("ccid").toString());
|
||||||
|
preparedStatement.setString(3,map.get("title").toString());
|
||||||
|
preparedStatement.setString(4,map.get("imgUrl").toString());
|
||||||
|
preparedStatement.setString(5,map.get("content").toString());
|
||||||
|
preparedStatement.setString(6,map.get("createDate").toString());
|
||||||
|
preparedStatement.setString(7,map.get("sort").toString());
|
||||||
|
// 添加到批处理中
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
res++;
|
||||||
|
if (res % 5000 == 0) {
|
||||||
|
long startTime1 = System.currentTimeMillis();
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
long spendTime1 = System.currentTimeMillis()-startTime1;
|
||||||
|
System.out.println("成功插入第"+ res +" 条数据,耗时:"+spendTime1+"毫秒");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//处理剩余的数据
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
long spendTime = System.currentTimeMillis()-startTime;
|
||||||
|
System.out.println("成功插入"+res+"条数据,耗时:"+spendTime+"毫秒");
|
||||||
|
fzdsconn.close();
|
||||||
|
yljkconn.close();
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void courseCatalogueChapterVideo(){
|
||||||
|
try {
|
||||||
|
Connection fzdsconn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?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");
|
||||||
|
ResultSet fzdsresultSet = fzdsstatement.executeQuery();
|
||||||
|
List<Map> fzdslist = new ArrayList();
|
||||||
|
while(fzdsresultSet.next()){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("uid",fzdsresultSet.getString("uid"));
|
||||||
|
map.put("cccid",fzdsresultSet.getString("cccid"));
|
||||||
|
map.put("title",fzdsresultSet.getString("title"));
|
||||||
|
fzdslist.add(map);
|
||||||
|
}
|
||||||
|
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_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
System.out.println("===== 开始插入数据 =====");
|
||||||
|
int res = 0;
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(
|
||||||
|
"INSERT ignore INTO course_catalogue_chapter_video (chapter_id,type,video,create_time,sort) VALUES (?, ?, ?, ?, ?)");
|
||||||
|
for (int q=1;q<=fzdslist.size(); q++){
|
||||||
|
String selectSql = "select * from t_curriculum_detail where valid = 1 and poid in (select oid from t_curriculum_catalogue where valid = 1 and poid = '"+fzdslist.get(q-1).get("uid")+"') and title = '"+fzdslist.get(q-1).get("title")+"' ";
|
||||||
|
PreparedStatement statement = yljkconn.prepareStatement(selectSql);
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
Map map = new HashMap();
|
||||||
|
while(resultSet.next()){
|
||||||
|
map.put("videoType",resultSet.getString("videoType"));
|
||||||
|
if (map.get("videoType").toString().equals("01")){
|
||||||
|
map.put("type","0");
|
||||||
|
map.put("video",resultSet.getString("videos"));
|
||||||
|
}else if (map.get("videoType").equals("02")){
|
||||||
|
map.put("type","1");
|
||||||
|
map.put("video",resultSet.getString("videoId"));
|
||||||
|
}
|
||||||
|
map.put("createDate",resultSet.getString("createDate"));
|
||||||
|
if (map.size() > 0){
|
||||||
|
String[] tt = map.get("video").toString().split(",");
|
||||||
|
if (tt.length>0){
|
||||||
|
for (int r=0;r<tt.length;r++){
|
||||||
|
if (!tt[r].equals("")) {
|
||||||
|
preparedStatement.setString(1,fzdslist.get(q-1).get("cccid").toString());
|
||||||
|
preparedStatement.setString(2,map.get("type").toString());
|
||||||
|
preparedStatement.setString(3,tt[r]);
|
||||||
|
preparedStatement.setString(4,map.get("createDate").toString());
|
||||||
|
preparedStatement.setString(5,r+1+"");
|
||||||
|
// 添加到批处理中
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
res++;
|
||||||
|
if (res % 5000 == 0) {
|
||||||
|
long startTime1 = System.currentTimeMillis();
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
long spendTime1 = System.currentTimeMillis()-startTime1;
|
||||||
|
System.out.println("成功插入第"+ res +" 条数据,耗时:"+spendTime1+"毫秒");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//处理剩余的数据
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
long spendTime = System.currentTimeMillis()-startTime;
|
||||||
|
System.out.println("成功插入"+res+"条数据,耗时:"+spendTime+"毫秒");
|
||||||
|
fzdsconn.close();
|
||||||
|
yljkconn.close();
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void user(){
|
||||||
|
try {
|
||||||
|
Connection fzdsconn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
|
||||||
|
"nuttyreading", "Wu751019!");
|
||||||
|
Connection yljkconn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?",
|
||||||
|
"yljkmaster", "Wu751019!@");
|
||||||
|
PreparedStatement statement = yljkconn.prepareStatement("select oid,cellPhone,nameCN,nickName,superVIP,point,pointByJF,payStatus,paydate,payValidDate from t_customer where valid = 1 ");
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
List<Map> list = new ArrayList();
|
||||||
|
while(resultSet.next()){
|
||||||
|
Map map = new HashMap();
|
||||||
|
map.put("oid",resultSet.getString("oid"));
|
||||||
|
map.put("cellPhone",resultSet.getString("cellPhone"));
|
||||||
|
map.put("nameCN",resultSet.getString("nameCN"));
|
||||||
|
map.put("nickName",resultSet.getString("nickName"));
|
||||||
|
map.put("superVIP",resultSet.getString("superVIP"));
|
||||||
|
map.put("point",resultSet.getString("point"));
|
||||||
|
map.put("pointByJF",resultSet.getString("pointByJF"));
|
||||||
|
map.put("payStatus",resultSet.getString("payStatus"));
|
||||||
|
map.put("paydate",resultSet.getString("paydate"));
|
||||||
|
map.put("payValidDate",resultSet.getString("payValidDate"));
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
statement.close();
|
||||||
|
for (int i=1;i<=list.size(); i++){
|
||||||
|
//已绑定过
|
||||||
|
PreparedStatement oidStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and yljk_oid = '"+list.get(i).get("oid")+"' ");
|
||||||
|
ResultSet oidResultSet = oidStatements.executeQuery();
|
||||||
|
if (oidResultSet.next()){
|
||||||
|
PreparedStatement oidUpdateStatement = fzdsconn.prepareStatement("update user_copy1 set " +
|
||||||
|
"name = if(isnull(name),"+list.get(i).get("nameCN")+") , nickname = if(isnull(nickname),"+list.get(i).get("nickName")+") ," +
|
||||||
|
"tel = if(isnull(tel),"+list.get(i).get("cellPhone")+") ," +
|
||||||
|
"vip= "+list.get(i).get("payStatus")+" ,peanut_coin = peanut_coin + "+list.get(i).get("point")+" , jf = jf + "+list.get(i).get("pointByJF")+" where id = "+oidResultSet.getString("id")+"");
|
||||||
|
oidUpdateStatement.executeUpdate();
|
||||||
|
if (list.get(i).get("payValidDate")!=null){
|
||||||
|
PreparedStatement oidInsertStatement = fzdsconn.prepareStatement(
|
||||||
|
"INSERT ignore INTO user_vip_copy1 (user_id,type,start_time,end_time,state) VALUES (?, ?, ?, ?, ?)");
|
||||||
|
oidInsertStatement.setString(1,oidResultSet.getString("id"));
|
||||||
|
oidInsertStatement.setString(2,list.get(i).get("payStatus").toString());
|
||||||
|
oidInsertStatement.setString(3,list.get(i).get("paydate").toString());
|
||||||
|
oidInsertStatement.setString(4,list.get(i).get("payValidDate").toString());
|
||||||
|
if (DateUtil.compare(DateUtil.parseDate(list.get(i).get("payValidDate").toString()),new Date())>0){
|
||||||
|
oidInsertStatement.setString(5,"0");
|
||||||
|
}else {
|
||||||
|
oidInsertStatement.setString(5,"1");
|
||||||
|
}
|
||||||
|
oidUpdateStatement.execute();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//未绑定过,用电话查询
|
||||||
|
PreparedStatement telStatements = fzdsconn.prepareStatement("select * from user_copy1 where del_flag = 0 and tel = '"+list.get(i).get("cellPhone")+"' ");
|
||||||
|
ResultSet telResultSet = telStatements.executeQuery();
|
||||||
|
if (telResultSet.next()){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.peanut.modules.common.entity;
|
package com.peanut.modules.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("course_market")
|
@TableName("course_market")
|
||||||
@@ -25,4 +27,7 @@ public class CourseMarketEntity {
|
|||||||
|
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer delFlag;
|
private Integer delFlag;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<CourseMarketEntity> children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class CourseToMarketEntity {
|
|||||||
|
|
||||||
private Integer courseId;
|
private Integer courseId;
|
||||||
|
|
||||||
private Integer sociologyId;
|
private Integer marketId;
|
||||||
|
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
package com.peanut.modules.master.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
|
import com.peanut.modules.common.entity.CourseEntity;
|
||||||
|
import com.peanut.modules.common.entity.CourseMarketEntity;
|
||||||
|
import com.peanut.modules.common.entity.CourseToMarketEntity;
|
||||||
|
import com.peanut.modules.master.service.CourseMarketService;
|
||||||
|
import com.peanut.modules.master.service.CourseService;
|
||||||
|
import com.peanut.modules.master.service.CourseToMarketService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
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.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController("masterCourseMarket")
|
||||||
|
@RequestMapping("master/courseMarket")
|
||||||
|
public class CourseMarketController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseMarketService marketService;
|
||||||
|
@Autowired
|
||||||
|
private CourseToMarketService toMarketService;
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 营销标签树
|
||||||
|
*/
|
||||||
|
@RequestMapping(path = "/marketTree")
|
||||||
|
public R marketTree() {
|
||||||
|
List<CourseMarketEntity> marketsTree = marketService.marketTree();
|
||||||
|
return R.ok().put("result", marketsTree);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取营销标签列表
|
||||||
|
*/
|
||||||
|
@RequestMapping(path = "/getMakertListByPid")
|
||||||
|
public R getMakertListByPid(String pid) {
|
||||||
|
LambdaQueryWrapper<CourseMarketEntity> wrapper = new LambdaQueryWrapper();
|
||||||
|
wrapper.eq(CourseMarketEntity::getPid,pid);
|
||||||
|
wrapper.orderByAsc(CourseMarketEntity::getSort);
|
||||||
|
wrapper.orderByAsc(CourseMarketEntity::getCreateTime);
|
||||||
|
List<CourseMarketEntity> marketTopList = marketService.list(wrapper);
|
||||||
|
return R.ok().put("result", marketTopList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = "/getMarketById")
|
||||||
|
public R getMarketById(String id) {
|
||||||
|
return R.ok().put("result",marketService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = "/saveOrUpdateMarket")
|
||||||
|
public R saveOrUpdateMarket(@RequestBody CourseMarketEntity market) {
|
||||||
|
if (market.getId()==null){
|
||||||
|
if(market.getPid()==0){
|
||||||
|
marketService.save(market);
|
||||||
|
return R.ok().put("result",market);
|
||||||
|
}else {
|
||||||
|
CourseMarketEntity m = marketService.getById(market.getPid());
|
||||||
|
if (m.getIsLast()==1){
|
||||||
|
return R.error("请将父标签设置为非最后一集");
|
||||||
|
}else {
|
||||||
|
marketService.save(market);
|
||||||
|
return R.ok().put("result",market);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (market.getIsLast() == 1){
|
||||||
|
List mList = marketService.list(new LambdaQueryWrapper<CourseMarketEntity>()
|
||||||
|
.eq(CourseMarketEntity::getPid,market.getId()));
|
||||||
|
if (mList.size()>0){
|
||||||
|
return R.error("请先删除子集,再设置为最后一集");
|
||||||
|
}else {
|
||||||
|
marketService.saveOrUpdate(market);
|
||||||
|
return R.ok().put("result",market);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
marketService.saveOrUpdate(market);
|
||||||
|
return R.ok().put("result",market);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = "/delMarket")
|
||||||
|
public R delMarket(String id) {
|
||||||
|
CourseMarketEntity market = marketService.getById(id);
|
||||||
|
if (market.getIsLast()==1){
|
||||||
|
MPJLambdaWrapper<CourseToMarketEntity> wrapper = new MPJLambdaWrapper();
|
||||||
|
wrapper.eq(CourseToMarketEntity::getMarketId,id);
|
||||||
|
List<CourseToMarketEntity> tomarkets = toMarketService.list(wrapper);
|
||||||
|
if (tomarkets.size()>0){
|
||||||
|
return R.error("请先移除课程");
|
||||||
|
}else {
|
||||||
|
marketService.removeById(id);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
List<CourseMarketEntity> marketList = marketService.list(new LambdaQueryWrapper<CourseMarketEntity>().eq(CourseMarketEntity::getPid,id));
|
||||||
|
if (marketList.size() > 0) {
|
||||||
|
return R.error("请先删除子集");
|
||||||
|
}else {
|
||||||
|
marketService.removeById(id);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取营销标签下课程
|
||||||
|
*/
|
||||||
|
@RequestMapping(path = "/getCourseByMarketId")
|
||||||
|
public R getCourseByMarket(@RequestBody Map<String, Object> params) {
|
||||||
|
MPJLambdaWrapper<CourseToMarketEntity> wrapper = new MPJLambdaWrapper();
|
||||||
|
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMarketEntity::getCourseId);
|
||||||
|
wrapper.selectAll(CourseEntity.class);
|
||||||
|
wrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||||
|
wrapper.eq(CourseToMarketEntity::getMarketId,params.get("marketId"));
|
||||||
|
Page res = toMarketService.pageMaps(new Page<>(
|
||||||
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
||||||
|
return R.ok().put("result", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未关联课程列表
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getNotToMarketList")
|
||||||
|
public R getNotToMarketList(@RequestBody Map params){
|
||||||
|
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper();
|
||||||
|
wrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||||
|
if (params.containsKey("marketId")&&!"".equals(params.get("marketId").toString())){
|
||||||
|
String sql = "select course_id from course_to_market where del_flag = 0 and market_id = "+params.get("marketId");
|
||||||
|
wrapper.notInSql(CourseEntity::getId,sql);
|
||||||
|
}
|
||||||
|
Page<CourseEntity> page = courseService.page(new Page<>(
|
||||||
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
|
||||||
|
return R.ok().put("result", page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = "/saveToMarket")
|
||||||
|
public R saveToMarket(@RequestBody Map params) {
|
||||||
|
if (!StringUtils.isEmpty(params.get("courseId").toString())){
|
||||||
|
String[] ids = params.get("courseId").toString().split(",");
|
||||||
|
if (ids.length > 0) {
|
||||||
|
for (String id : ids) {
|
||||||
|
CourseToMarketEntity toMarket = new CourseToMarketEntity();
|
||||||
|
toMarket.setMarketId(Integer.parseInt(params.get("marketId").toString()));
|
||||||
|
toMarket.setCourseId(Integer.parseInt(id));
|
||||||
|
toMarketService.save(toMarket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = "/delToMarket")
|
||||||
|
public R delToMarket(String marketId,String courseId) {
|
||||||
|
if(StringUtils.isNotEmpty(courseId)){
|
||||||
|
String[] productIds = courseId.split(",");
|
||||||
|
for(String id : productIds){
|
||||||
|
LambdaQueryWrapper<CourseToMarketEntity> wrapper = new LambdaQueryWrapper();
|
||||||
|
wrapper.eq(CourseToMarketEntity::getMarketId,marketId);
|
||||||
|
wrapper.eq(CourseToMarketEntity::getCourseId,id);
|
||||||
|
toMarketService.remove(wrapper);
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.error("参数为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.peanut.modules.master.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.CourseMarketEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CourseMarketService extends IService<CourseMarketEntity> {
|
||||||
|
|
||||||
|
List<CourseMarketEntity> marketTree();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.peanut.modules.master.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.CourseToMarketEntity;
|
||||||
|
|
||||||
|
public interface CourseToMarketService extends IService<CourseToMarketEntity> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.peanut.modules.master.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.CourseMarketDao;
|
||||||
|
import com.peanut.modules.common.entity.CourseMarketEntity;
|
||||||
|
import com.peanut.modules.master.service.CourseMarketService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("masterCourseMarketService")
|
||||||
|
public class CourseMarketServiceImpl extends ServiceImpl<CourseMarketDao, CourseMarketEntity> implements CourseMarketService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseMarketDao marketDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CourseMarketEntity> marketTree() {
|
||||||
|
List<CourseMarketEntity> markets = marketDao.selectList(new QueryWrapper<>());
|
||||||
|
List<CourseMarketEntity> marketsTree = markets.stream().filter((courseMarketEntity) ->
|
||||||
|
courseMarketEntity.getPid() == 0
|
||||||
|
).map((market)->{
|
||||||
|
market.setChildren(getMarketChildrens(market,markets));
|
||||||
|
return market;
|
||||||
|
}).sorted((sort1,sort2)->{
|
||||||
|
return (sort1.getSort() == null? 0 : sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return marketsTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CourseMarketEntity> getMarketChildrens(CourseMarketEntity root,List<CourseMarketEntity> all){
|
||||||
|
List<CourseMarketEntity> children = all.stream().filter(courseMarketEntity -> {
|
||||||
|
return root.getId().equals(courseMarketEntity.getPid());
|
||||||
|
}).map(courseMarketEntity -> {
|
||||||
|
courseMarketEntity.setChildren(getMarketChildrens(courseMarketEntity, all));
|
||||||
|
return courseMarketEntity;
|
||||||
|
}).sorted((sort1,sort2)->{
|
||||||
|
return (sort1.getSort()==null?0:sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.peanut.modules.master.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.CourseToMarketDao;
|
||||||
|
import com.peanut.modules.common.entity.CourseToMarketEntity;
|
||||||
|
import com.peanut.modules.master.service.CourseToMarketService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("masterCourseToMarketService")
|
||||||
|
public class CourseToMarketServiceImpl extends ServiceImpl<CourseToMarketDao, CourseToMarketEntity> implements CourseToMarketService {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user