From d9361b75e7072b29535c571a76e0b9e7860d6805 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 06 Jan 2025 14:38:53 +0800
Subject: [PATCH] feat(mall): 后台活动列表添加分页和搜索功能 - 在 ActivityServiceImpl 中实现 getAdminListInPage 方法,支持分页和搜索 - 在 AdminActivityController 中添加 list 接口,返回分页数据 - 在 IActivityService 中定义 getAdminListInPage 接口 - 更新前端模板,根据活动状态控制按钮显示

---
 src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberCollectionServiceImpl.java |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberCollectionServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberCollectionServiceImpl.java
index a70cb57..5d606cf 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberCollectionServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberCollectionServiceImpl.java
@@ -1,11 +1,14 @@
 package cc.mrbird.febs.mall.service.impl;
 
+import cc.mrbird.febs.common.exception.FebsException;
 import cc.mrbird.febs.common.utils.LoginUserUtil;
 import cc.mrbird.febs.mall.dto.AddCollectionDto;
 import cc.mrbird.febs.mall.dto.MemberCollectionListDto;
+import cc.mrbird.febs.mall.entity.MallGoods;
 import cc.mrbird.febs.mall.entity.MallMember;
 import cc.mrbird.febs.mall.entity.MallMemberCollection;
 import cc.mrbird.febs.mall.mapper.MallMemberCollectionMapper;
+import cc.mrbird.febs.mall.service.IApiMallGoodsService;
 import cc.mrbird.febs.mall.service.IMallMemberCollectionService;
 import cc.mrbird.febs.mall.vo.AddCollectionVo;
 import cc.mrbird.febs.mall.vo.CollectionListVo;
@@ -29,9 +32,24 @@
 @RequiredArgsConstructor
 public class MallMemberCollectionServiceImpl extends ServiceImpl<MallMemberCollectionMapper, MallMemberCollection> implements IMallMemberCollectionService {
 
+    private final IApiMallGoodsService apiMallGoodsService;
+
     @Override
     public void add(AddCollectionDto addCollectionDto) {
         MallMember member = LoginUserUtil.getLoginUser();
+
+        MallGoods mallgoods = apiMallGoodsService.getById(addCollectionDto.getGoodsId());
+        if (mallgoods == null) {
+            throw new FebsException("商品不存在");
+        }
+
+        LambdaQueryWrapper<MallMemberCollection> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(MallMemberCollection::getMemberId, member.getId());
+        queryWrapper.eq(MallMemberCollection::getGoodsId, addCollectionDto.getGoodsId());
+        List<MallMemberCollection> mallMemberCollections = this.baseMapper.selectList(queryWrapper);
+        if (CollUtil.isNotEmpty(mallMemberCollections)) {
+            throw new FebsException("商品已收藏");
+        }
 
         MallMemberCollection collection = new MallMemberCollection();
         collection.setMemberId(member.getId());
@@ -58,8 +76,14 @@
     @Override
     public void del(String ids) {
         MallMember member = LoginUserUtil.getLoginUser();
-        List<String> idsList = StrUtil.split(ids, ',');
+        List<String> goodsIdList = StrUtil.split(ids, ',');
 
+        LambdaQueryWrapper<MallMemberCollection> query = new LambdaQueryWrapper<>();
+        query.in(MallMemberCollection::getGoodsId, goodsIdList);
+        query.eq(MallMemberCollection::getMemberId, member.getId());
+        List<MallMemberCollection> collections = this.baseMapper.selectList(query);
+
+        List<Long> idsList = collections.stream().map(MallMemberCollection::getId).collect(Collectors.toList());
         LambdaQueryWrapper<MallMemberCollection> delQuery = new LambdaQueryWrapper<>();
         delQuery.in(MallMemberCollection::getId, idsList);
         delQuery.eq(MallMemberCollection::getMemberId, member.getId());

--
Gitblit v1.9.1