From a855db66a9f29cc1c45ed080097a56ec02ad87f8 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 19 Apr 2024 10:39:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=AB=AF-=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=90=A5=E9=94=80=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/DataMigrationUtil.java | 43 +++-- .../common/entity/CourseMarketEntity.java | 5 + .../common/entity/CourseToMarketEntity.java | 2 +- .../controller/CourseMarketController.java | 179 ++++++++++++++++++ .../master/service/CourseMarketService.java | 12 ++ .../master/service/CourseToMarketService.java | 7 + .../service/impl/CourseMarketServiceImpl.java | 48 +++++ .../impl/CourseToMarketServiceImpl.java | 13 ++ 8 files changed, 294 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/peanut/modules/master/controller/CourseMarketController.java create mode 100644 src/main/java/com/peanut/modules/master/service/CourseMarketService.java create mode 100644 src/main/java/com/peanut/modules/master/service/CourseToMarketService.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/CourseMarketServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/CourseToMarketServiceImpl.java diff --git a/src/main/java/com/peanut/common/utils/DataMigrationUtil.java b/src/main/java/com/peanut/common/utils/DataMigrationUtil.java index b8f5c03d..f5ec8679 100644 --- a/src/main/java/com/peanut/common/utils/DataMigrationUtil.java +++ b/src/main/java/com/peanut/common/utils/DataMigrationUtil.java @@ -1,8 +1,11 @@ package com.peanut.common.utils; -import java.io.IOException; +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 { @@ -13,7 +16,7 @@ public class DataMigrationUtil { // courseCatalogue(); // courseCatalogueChapter(); // courseCatalogueChapterVideo(); - + user(); } @@ -303,8 +306,8 @@ public class DataMigrationUtil { public static void user(){ try { Connection fzdsconn = DriverManager.getConnection( - "jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?", - "yljkmaster", "Wu751019!@"); + "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!@"); @@ -331,19 +334,31 @@ public class DataMigrationUtil { //已绑定过 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.wasNull()){ + 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.wasNull()){ - - } - }else { - while(resultSet.next()){ - PreparedStatement oidStatement = fzdsconn.prepareStatement("update user_copy1 set " + - "name = if(isnull(name),"+list.get(i).get("nameCN")+",name) , nickname = if(isnull(nickname),"+list.get(i).get("nickName")+",nickname) ," + - "tel = if(isnull(tel),"+list.get(i).get("cellPhone")+",tel) ," + - "vip= "+list.get(i).get("payStatus")+" ,peanut_coin = peanut_coin + "+list.get(i).get("point")+" , jf = jf + "+list.get(i).get("pointByJF")+" where id = "+resultSet.getString("id")+""); + if (telResultSet.next()){ } } diff --git a/src/main/java/com/peanut/modules/common/entity/CourseMarketEntity.java b/src/main/java/com/peanut/modules/common/entity/CourseMarketEntity.java index fe176fa0..c0674a40 100644 --- a/src/main/java/com/peanut/modules/common/entity/CourseMarketEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/CourseMarketEntity.java @@ -1,11 +1,13 @@ 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; +import java.util.List; @Data @TableName("course_market") @@ -25,4 +27,7 @@ public class CourseMarketEntity { @TableLogic private Integer delFlag; + + @TableField(exist = false) + private List children; } diff --git a/src/main/java/com/peanut/modules/common/entity/CourseToMarketEntity.java b/src/main/java/com/peanut/modules/common/entity/CourseToMarketEntity.java index 0cf4f244..87e894fe 100644 --- a/src/main/java/com/peanut/modules/common/entity/CourseToMarketEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/CourseToMarketEntity.java @@ -16,7 +16,7 @@ public class CourseToMarketEntity { private Integer courseId; - private Integer sociologyId; + private Integer marketId; private Date createTime; diff --git a/src/main/java/com/peanut/modules/master/controller/CourseMarketController.java b/src/main/java/com/peanut/modules/master/controller/CourseMarketController.java new file mode 100644 index 00000000..bba0d8d0 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/controller/CourseMarketController.java @@ -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 marketsTree = marketService.marketTree(); + return R.ok().put("result", marketsTree); + } + + /** + * 获取营销标签列表 + */ + @RequestMapping(path = "/getMakertListByPid") + public R getMakertListByPid(String pid) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.eq(CourseMarketEntity::getPid,pid); + wrapper.orderByAsc(CourseMarketEntity::getSort); + wrapper.orderByAsc(CourseMarketEntity::getCreateTime); + List 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() + .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 wrapper = new MPJLambdaWrapper(); + wrapper.eq(CourseToMarketEntity::getMarketId,id); + List tomarkets = toMarketService.list(wrapper); + if (tomarkets.size()>0){ + return R.error("请先移除课程"); + }else { + marketService.removeById(id); + return R.ok(); + } + }else { + List marketList = marketService.list(new LambdaQueryWrapper().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 params) { + MPJLambdaWrapper 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 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 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 wrapper = new LambdaQueryWrapper(); + wrapper.eq(CourseToMarketEntity::getMarketId,marketId); + wrapper.eq(CourseToMarketEntity::getCourseId,id); + toMarketService.remove(wrapper); + } + return R.ok(); + } + return R.error("参数为空"); + } + +} diff --git a/src/main/java/com/peanut/modules/master/service/CourseMarketService.java b/src/main/java/com/peanut/modules/master/service/CourseMarketService.java new file mode 100644 index 00000000..004c8a10 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/CourseMarketService.java @@ -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 { + + List marketTree(); + +} diff --git a/src/main/java/com/peanut/modules/master/service/CourseToMarketService.java b/src/main/java/com/peanut/modules/master/service/CourseToMarketService.java new file mode 100644 index 00000000..1688417a --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/CourseToMarketService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/CourseMarketServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/CourseMarketServiceImpl.java new file mode 100644 index 00000000..ca4957d9 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/CourseMarketServiceImpl.java @@ -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 implements CourseMarketService { + + + @Autowired + private CourseMarketDao marketDao; + + @Override + public List marketTree() { + List markets = marketDao.selectList(new QueryWrapper<>()); + List 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 getMarketChildrens(CourseMarketEntity root,List all){ + List 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; + } + +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/CourseToMarketServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/CourseToMarketServiceImpl.java new file mode 100644 index 00000000..3d9c4eb0 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/CourseToMarketServiceImpl.java @@ -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 implements CourseToMarketService { +}