|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.mapper.MallGoodsCategoryMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallGoodsMapper; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IAdminMallGoodsCategoryService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryTreeVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryVo; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public IPage<MallGoodsCategory> getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallGoodsCategory goodsCategory = new MallGoodsCategory(); | 
|---|
|  |  |  | goodsCategory.setName(name); | 
|---|
|  |  |  | goodsCategory.setImage(mallGoodsCategory.getImage()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallGoodsCategory.getParentId())){ | 
|---|
|  |  |  | Long parentId = mallGoodsCategory.getParentId(); | 
|---|
|  |  |  | MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|