From 91f4ccc2b11c6981f560d32449a655f9578ce51e Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Mon, 24 Feb 2025 17:31:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E7=81=B5=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShopProductController.java | 28 +++++ .../master/service/ShopProductService.java | 8 ++ .../impl/CourseMedicineServiceImpl.java | 2 +- .../service/impl/ShopProductServiceImpl.java | 106 +++++++++++++++++- .../controller/PsycheCourseController.java | 12 +- 5 files changed, 152 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/peanut/modules/master/controller/ShopProductController.java b/src/main/java/com/peanut/modules/master/controller/ShopProductController.java index 98ca2481..80479b77 100644 --- a/src/main/java/com/peanut/modules/master/controller/ShopProductController.java +++ b/src/main/java/com/peanut/modules/master/controller/ShopProductController.java @@ -131,6 +131,34 @@ public class ShopProductController { return R.ok(); } + @RequestMapping("/bindProductAndPsycheLabel") + public R bindProductAndPsycheLabel(@RequestBody Map map){ + String[] productIds = map.get("productId").split(","); + Integer labelId = Integer.valueOf(map.get("labelId")); + shopProductService.bindProductAndPsycheLabel(productIds,labelId); + return R.ok(); + } + + @RequestMapping("/unbindProductAndPsycheLabel") + public R unbindProductAndPsycheLabel(@RequestBody Map map){ + shopProductService.unbindProductAndPsycheLabel(map.get("productId"),map.get("labelId")); + return R.ok(); + } + + @RequestMapping("/bindProductAndPsycheMarket") + public R bindProductAndPsycheMarket(@RequestBody Map map){ + String[] productIds = map.get("productId").split(","); + Integer marketId = Integer.valueOf(map.get("marketId")); + shopProductService.bindProductAndPsycheMarket(productIds,marketId); + return R.ok(); + } + + @RequestMapping("/unbindProductAndPsycheMarket") + public R unbindProductAndPsycheMarket(@RequestBody Map map){ + shopProductService.unbindProductAndPsycheMarket(map.get("productId"),map.get("marketId")); + return R.ok(); + } + @RequestMapping("/bindProductAndMedicineLabel") public R bindProductAndMedicineLabel(@RequestBody Map map){ String[] productIds = map.get("productId").split(","); diff --git a/src/main/java/com/peanut/modules/master/service/ShopProductService.java b/src/main/java/com/peanut/modules/master/service/ShopProductService.java index 463a27cd..bc371826 100644 --- a/src/main/java/com/peanut/modules/master/service/ShopProductService.java +++ b/src/main/java/com/peanut/modules/master/service/ShopProductService.java @@ -33,6 +33,14 @@ public interface ShopProductService extends IService { void unbindProductAndSociologyMarket(int product,int marketId); + void bindProductAndPsycheLabel(String[] productIds,Integer labelId); + + void unbindProductAndPsycheLabel(int productId,int labelId); + + void bindProductAndPsycheMarket(String[] productId,int marketId); + + void unbindProductAndPsycheMarket(int product,int marketId); + void bindProductAndMedicineLabel(String[] productId,int labelId); void unbindProductAndMedicineLabel(int productId,int labelId); diff --git a/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java index d3e07550..5f3903a3 100644 --- a/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java +++ b/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java @@ -36,7 +36,7 @@ public class CourseMedicineServiceImpl extends ServiceImpl().eq(CourseToMedicine::getMedicalId, id)); if(integer>0){ - return R.error(502,"删除失败,请先解绑课程与国学标签的绑定关系"); + return R.error(502,"删除失败,请先解绑课程与医学标签的绑定关系"); } this.removeById(id); return R.ok(); diff --git a/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java index 2120e70d..4480ff25 100644 --- a/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java +++ b/src/main/java/com/peanut/modules/master/service/impl/ShopProductServiceImpl.java @@ -52,6 +52,14 @@ public class ShopProductServiceImpl extends ServiceImpl().eq(ShopProductToSociologyMarket::getProductId,product).eq(ShopProductToSociologyMarket::getSociologyMarketId,marketId)); } + @Override + public void bindProductAndPsycheLabel(String[] productIds, Integer labelId) { + for (String p : productIds){ + Integer integer = shopProductToPsycheLabelDao.selectCount(new LambdaQueryWrapper().eq(ShopProductToPsycheLabel::getProductId, Integer.valueOf(p)).eq(ShopProductToPsycheLabel::getPsycheLabelId, labelId)); + if(integer>0){ + continue; + } + ShopProductToPsycheLabel shopProductToPsycheLabel = new ShopProductToPsycheLabel(); + shopProductToPsycheLabel.setProductId(Integer.valueOf(p)); + shopProductToPsycheLabel.setPsycheLabelId(labelId); + shopProductToPsycheLabelDao.insert(shopProductToPsycheLabel); + } + } + + @Override + public void unbindProductAndPsycheLabel(int productId, int labelId) { + shopProductToPsycheLabelDao.delete(new LambdaQueryWrapper().eq(ShopProductToPsycheLabel::getProductId, productId).eq(ShopProductToPsycheLabel::getPsycheLabelId, labelId)); + } + + @Override + public void bindProductAndPsycheMarket(String[] productId, int marketId) { + for (String p:productId){ + Integer integer = shopProductToPsycheMarketDao.selectCount(new LambdaQueryWrapper().eq(ShopProductToPsycheMarket::getProductId, Integer.valueOf(p)).eq(ShopProductToPsycheMarket::getPsycheMarketId, marketId)); + if(integer>0){ + continue; + } + ShopProductToPsycheMarket shopProductToPsycheMarket = new ShopProductToPsycheMarket(); + shopProductToPsycheMarket.setProductId(Integer.valueOf(p)); + shopProductToPsycheMarket.setPsycheMarketId(marketId); + shopProductToPsycheMarketDao.insert(shopProductToPsycheMarket); + } + } + + @Override + public void unbindProductAndPsycheMarket(int product, int marketId) { + shopProductToPsycheMarketDao.delete(new LambdaQueryWrapper().eq(ShopProductToPsycheMarket::getProductId,product).eq(ShopProductToPsycheMarket::getPsycheMarketId,marketId)); + } + @Override public void bindProductAndMedicineLabel(String[] productId, int labelId) { for (String p : productId){ @@ -405,7 +451,34 @@ public class ShopProductServiceImpl extends ServiceImpl psycheLabelIds = shopProductToPsycheLabelDao.selectList(new LambdaQueryWrapper().eq(ShopProductToPsycheLabel::getProductId, productId)).stream().map(ShopProductToPsycheLabel::getPsycheLabelId).collect(Collectors.toList()); + List shopProductPsycheLabels = shopProductPsycheLabelDao.selectList(null); + List psycheLabel = shopProductPsycheLabels.stream().filter(m -> m.getPid() == 0) + .map((m) -> { + if (m.getIsLast() == 1) { + m.setSelect(psycheLabelIds.contains(m.getId())); + } + m.setChildren(getPsycheLabelChildrens(m, shopProductPsycheLabels, psycheLabelIds)); + return m; + }).sorted((label1, label2) -> { + return (label1.getSort() == null ? 0 : label1.getSort()) - (label2.getSort() == null ? 0 : label2.getSort()); + }).collect(Collectors.toList()); + flag.put("psycheLabel",psycheLabel); + //心理学运营标签 + List psycheMarketIds = shopProductToPsycheMarketDao.selectList(new LambdaQueryWrapper().eq(ShopProductToPsycheMarket::getProductId, productId)).stream().map(ShopProductToPsycheMarket::getPsycheMarketId).collect(Collectors.toList()); + List shopProductPsycheMarkets = shopProductPsycheMarketDao.selectList(null); + List psycheMarket = shopProductPsycheMarkets.stream().filter(m -> m.getPid() == 0) + .map((m) -> { + if (m.getIsLast() == 1) { + m.setSelect(psycheMarketIds.contains(m.getId())); + } + m.setChildren(getPsycheMarketChildrens(m, shopProductPsycheMarkets, psycheMarketIds)); + return m; + }).sorted((label1, label2) -> { + return (label1.getSort() == null ? 0 : label1.getSort()) - (label2.getSort() == null ? 0 : label2.getSort()); + }).collect(Collectors.toList()); + flag.put("psycheMarket",psycheMarket); return flag; } @@ -503,4 +576,35 @@ public class ShopProductServiceImpl extends ServiceImpl getPsycheLabelChildrens(ShopProductPsycheLabel root,List all,List ids){ + List children = all.stream().filter((m) -> { + return m.getPid().equals(root.getId()); + }) + .map((m) -> { + if (m.getIsLast() == 1) { + m.setSelect(ids.contains(m.getId())); + } + m.setChildren(getPsycheLabelChildrens(m, all, ids)); + return m; + }).sorted((label1, label2) -> { + return (label1.getSort() == null ? 0 : label1.getSort()) - (label2.getSort() == null ? 0 : label2.getSort()); + }).collect(Collectors.toList()); + return children; + } + private List getPsycheMarketChildrens(ShopProductPsycheMarket root,List all,List ids){ + List children = all.stream().filter((m) -> { + return m.getPid().equals(root.getId()); + }) + .map((m) -> { + if (m.getIsLast() == 1) { + m.setSelect(ids.contains(m.getId())); + } + m.setChildren(getPsycheMarketChildrens(m, all, ids)); + return m; + }).sorted((label1, label2) -> { + return (label1.getSort() == null ? 0 : label1.getSort()) - (label2.getSort() == null ? 0 : label2.getSort()); + }).collect(Collectors.toList()); + return children; + } } diff --git a/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java index c01bdf99..9a88e6c2 100644 --- a/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java +++ b/src/main/java/com/peanut/modules/psyche/controller/PsycheCourseController.java @@ -39,8 +39,10 @@ public class PsycheCourseController { public R getUserCourseBuy(){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId); - wrapper.leftJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); - wrapper.leftJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCourseId,CourseEntity::getId); + wrapper.rightJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId); + if (!userVipService.isPsycheVip()){ + wrapper.leftJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCourseId,CourseEntity::getId); + } wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId()); wrapper.selectAll(CourseEntity.class); wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId"); @@ -48,6 +50,12 @@ public class PsycheCourseController { wrapper.orderByAsc(CourseEntity::getSort); wrapper.orderByAsc(CourseCatalogueEntity::getSort); List> courseList = courseService.listMaps(wrapper); + for (Map map:courseList){ + int i = userCourseStudyingService.count(new LambdaQueryWrapper() + .eq(UserCourseStudying::getCourseId,map.get("id")) + .eq(UserCourseStudying::getUserId,ShiroUtils.getUId())); + map.put("isStudying",i>0?1:0); + } return R.ok().put("courseList",courseList); }