From e8df19e3efe5a5cda98997ea2b20c039990a0ab8 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Sun, 26 Sep 2021 16:48:12 +0800 Subject: [PATCH] fix --- src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 54 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 57d4875..0ebe802 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 @@ -5,6 +5,8 @@ import cc.mrbird.febs.mall.entity.MallGoodsCategory; import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper; 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; import cn.hutool.core.util.StrUtil; @@ -41,10 +43,14 @@ 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()); if(ObjectUtil.isNotEmpty(mallGoodsCategory.getParentId())){ Long parentId = mallGoodsCategory.getParentId(); MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); @@ -54,8 +60,10 @@ }else{ goodsCategory.setParentIds(mallGoodsCategory.getParentId()+","); } + goodsCategory.setIsRecommend(0); }else{ goodsCategory.setParentId(0L); + goodsCategory.setIsRecommend(mallGoodsCategory.getIsRecommend()); } mallGoodsCategoryMapper.insert(goodsCategory); return new FebsResponse().success(); @@ -67,4 +75,49 @@ return mallGoodsCategorys; } + @Override + public AdminMallGoodsCategoryVo getMallGoodsCategoryInfoById(long id) { + 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()); + 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(); + } + } -- Gitblit v1.9.1