From 59da87cc7b9db21b01c8c2c0831619aff73d0f84 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 28 Apr 2025 17:54:27 +0800
Subject: [PATCH] fix(mall): 修复活动订单删除功能

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java |  155 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 154 insertions(+), 1 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java
index 2b4b187..1201a68 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java
@@ -2,9 +2,16 @@
 
 import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.entity.QueryRequest;
+import cc.mrbird.febs.mall.entity.MallGoods;
 import cc.mrbird.febs.mall.entity.MallGoodsCategory;
+import cc.mrbird.febs.mall.entity.MallStore;
+import cc.mrbird.febs.mall.entity.MallStoreItem;
 import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper;
+import cc.mrbird.febs.mall.mapper.MallGoodsMapper;
+import cc.mrbird.febs.mall.mapper.MallStoreItemMapper;
+import cc.mrbird.febs.mall.mapper.MallStoreMapper;
 import cc.mrbird.febs.mall.service.IAdminMallGoodsCategoryService;
+import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryTreeVo;
 import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryVo;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
@@ -15,15 +22,21 @@
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
 @Slf4j
 @Service
 @RequiredArgsConstructor
+@Transactional
 public class AdminMallGoodsCategoryService extends ServiceImpl<MallGoodsCategoryMapper, MallGoodsCategory> implements IAdminMallGoodsCategoryService {
 
     private final MallGoodsCategoryMapper mallGoodsCategoryMapper;
+
+    private final MallGoodsMapper mallGoodsMapper;
+    private final MallStoreMapper mallStoreMapper;
+    private final MallStoreItemMapper mallStoreItemMapper;
 
     @Override
     public IPage<MallGoodsCategory> getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) {
@@ -42,10 +55,15 @@
         if(CollUtil.isNotEmpty(categorys)){
             return new FebsResponse().fail().message("分类名称不能重复");
         }
+        Long parentIdParam = mallGoodsCategory.getParentId() == null ? 0L:mallGoodsCategory.getParentId();
+        Integer isRecommendParam = mallGoodsCategory.getIsRecommend();
+        if(parentIdParam > 0 && isRecommendParam == 1){
+            return new FebsResponse().fail().message("子分类不能选择【是否推荐】为【是】");
+        }
 
         MallGoodsCategory goodsCategory = new MallGoodsCategory();
         goodsCategory.setName(name);
-        goodsCategory.setIsRecommend(mallGoodsCategory.getIsRecommend());
+        goodsCategory.setImage(mallGoodsCategory.getImage());
         if(ObjectUtil.isNotEmpty(mallGoodsCategory.getParentId())){
             Long parentId = mallGoodsCategory.getParentId();
             MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId);
@@ -55,8 +73,10 @@
             }else{
                 goodsCategory.setParentIds(mallGoodsCategory.getParentId()+",");
             }
+            goodsCategory.setIsRecommend(0);
         }else{
             goodsCategory.setParentId(0L);
+            goodsCategory.setIsRecommend(mallGoodsCategory.getIsRecommend());
         }
         mallGoodsCategoryMapper.insert(goodsCategory);
         return new FebsResponse().success();
@@ -73,4 +93,137 @@
         return mallGoodsCategoryMapper.getMallGoodsCategoryInfoById(id);
     }
 
+    @Override
+    public List<AdminMallGoodsCategoryTreeVo> getParentCategorys() {
+        List<AdminMallGoodsCategoryTreeVo> adminMallGoodsCategoryTreeVos = mallGoodsCategoryMapper.getParentCategorys();
+        return adminMallGoodsCategoryTreeVos;
+    }
+
+    @Override
+    public FebsResponse updateCategory(MallGoodsCategory mallGoodsCategoryParam) {
+        String name = mallGoodsCategoryParam.getName();
+        if(StrUtil.isEmpty(name)){
+            return new FebsResponse().fail().message("名称不能为空");
+        }
+        Long parentIdParam = mallGoodsCategoryParam.getParentId() == null ? 0L:mallGoodsCategoryParam.getParentId();
+        Integer isRecommendParam = mallGoodsCategoryParam.getIsRecommend();
+        if(parentIdParam > 0 && isRecommendParam == 1){
+            return new FebsResponse().fail().message("子分类不能选择【是否推荐】为【是】");
+        }
+
+        Long id = mallGoodsCategoryParam.getId();
+        MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id);
+        mallGoodsCategory.setName(mallGoodsCategoryParam.getName());
+        mallGoodsCategory.setImage(mallGoodsCategoryParam.getImage());
+        mallGoodsCategory.setIndexNum(mallGoodsCategoryParam.getIndexNum());
+        if(ObjectUtil.isNotEmpty(mallGoodsCategoryParam.getParentId())){
+            Long parentId = mallGoodsCategoryParam.getParentId();
+            MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId);
+            mallGoodsCategory.setParentId(mallGoodsCategoryParam.getParentId());
+            if(StrUtil.isNotEmpty(mallGoodsCategoryParent.getParentIds())){
+                mallGoodsCategory.setParentIds(mallGoodsCategoryParent.getParentIds()+","+mallGoodsCategory.getParentId()+",");
+            }else{
+                mallGoodsCategory.setParentIds(mallGoodsCategory.getParentId()+",");
+            }
+            mallGoodsCategory.setIsRecommend(0);
+        }else{
+            mallGoodsCategory.setParentId(0L);
+            mallGoodsCategory.setIsRecommend(mallGoodsCategoryParam.getIsRecommend());
+        }
+        mallGoodsCategoryMapper.updateById(mallGoodsCategory);
+
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public FebsResponse delCategary(Long id) {
+        MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id);
+        if(ObjectUtil.isEmpty(mallGoodsCategory)){
+            return new FebsResponse().fail().message("系统繁忙,请刷新页面重试");
+        }
+        List<MallGoodsCategory> childCategarys = mallGoodsCategoryMapper.selectChildCategaryById(id);
+        if(CollUtil.isNotEmpty(childCategarys)){
+            for(MallGoodsCategory childCategary : childCategarys){
+                Long childCategaryId = childCategary.getId();
+                List<MallGoods> mallChildGoods = mallGoodsMapper.selectMallGoodsByCategaryId(childCategaryId);
+                if(CollUtil.isNotEmpty(mallChildGoods)){
+                    return new FebsResponse().fail().message("该分类下的子类【"+childCategary.getName()+"】还有商品,请先删除商品或者修改商品分类");
+                }
+            }
+        }
+
+        if(CollUtil.isNotEmpty(childCategarys)){
+            return new FebsResponse().fail().message("该分类下还有子类,请先删除子类");
+        }
+
+        List<MallGoods> mallGoods = mallGoodsMapper.selectMallGoodsByCategaryId(id);
+        if(CollUtil.isNotEmpty(mallGoods)){
+            return new FebsResponse().fail().message("该分类下还有商品,请先删除商品或者修改商品分类");
+        }
+        mallGoodsCategoryMapper.deleteById(mallGoodsCategory);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public List<AdminMallGoodsCategoryTreeVo> getAllCategorys() {
+        List<AdminMallGoodsCategoryTreeVo> adminMallGoodsCategoryTreeVos = mallGoodsCategoryMapper.getAllCategorys();
+        return adminMallGoodsCategoryTreeVos;
+    }
+
+    @Override
+    public IPage<MallStore> storeList(MallStore mallStore, QueryRequest request) {
+        Page<MallStore> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<MallStore> mallStoreIPage = mallGoodsCategoryMapper.selectStoreListInPage(page, mallStore);
+        return mallStoreIPage;
+    }
+
+    @Override
+    public FebsResponse addStore(MallStore mallStore) {
+        mallStoreMapper.insert(mallStore);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public FebsResponse updateStore(MallStore mallStore) {
+        mallStoreMapper.updateById(mallStore);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public FebsResponse delStore(Long id) {
+        mallStoreMapper.deleteById(id);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public IPage<MallStoreItem> storeItemList(MallStoreItem mallStoreItem, QueryRequest request) {
+        Page<MallStoreItem> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<MallStoreItem> mallStoreItemIPage = mallGoodsCategoryMapper.selectStoreItemListInPage(page, mallStoreItem);
+        return mallStoreItemIPage;
+    }
+
+    @Override
+    public List<MallStore> getStore() {
+        List<MallStore> mallStores = mallGoodsCategoryMapper.getStore();
+        return mallStores;
+    }
+
+    @Override
+    public FebsResponse addStoreItem(MallStoreItem mallStoreItem) {
+        mallStoreItemMapper.insert(mallStoreItem);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public FebsResponse updateStoreItem(MallStoreItem mallStoreItem) {
+        mallStoreItemMapper.updateById(mallStoreItem);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public FebsResponse delStoreItem(Long id) {
+        mallStoreItemMapper.deleteById(id);
+        return new FebsResponse().success();
+    }
+
 }

--
Gitblit v1.9.1