package cc.mrbird.febs.mall.service.impl; 
 | 
  
 | 
import cc.mrbird.febs.common.entity.FebsResponse; 
 | 
import cc.mrbird.febs.common.entity.QueryRequest; 
 | 
import cc.mrbird.febs.mall.entity.MallGoodsCategory; 
 | 
import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper; 
 | 
import cc.mrbird.febs.mall.service.IAdminMallGoodsCategoryService; 
 | 
import cn.hutool.core.collection.CollUtil; 
 | 
import cn.hutool.core.util.ObjectUtil; 
 | 
import cn.hutool.core.util.StrUtil; 
 | 
import com.baomidou.mybatisplus.core.metadata.IPage; 
 | 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
 | 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
 | 
import lombok.RequiredArgsConstructor; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.springframework.stereotype.Service; 
 | 
  
 | 
import java.util.List; 
 | 
  
 | 
@Slf4j 
 | 
@Service 
 | 
@RequiredArgsConstructor 
 | 
public class AdminMallGoodsCategoryService extends ServiceImpl<MallGoodsCategoryMapper, MallGoodsCategory> implements IAdminMallGoodsCategoryService { 
 | 
  
 | 
    private final MallGoodsCategoryMapper mallGoodsCategoryMapper; 
 | 
  
 | 
    @Override 
 | 
    public IPage<MallGoodsCategory> getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) { 
 | 
        Page<MallGoodsCategory> page = new Page<>(request.getPageNum(), request.getPageSize()); 
 | 
        IPage<MallGoodsCategory> mallGoodsCategorys = this.baseMapper.selectCategoryList(page, mallGoodsCategory); 
 | 
        return mallGoodsCategorys; 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public FebsResponse addCategory(MallGoodsCategory mallGoodsCategory) { 
 | 
        String name = mallGoodsCategory.getName(); 
 | 
        if(StrUtil.isEmpty(name)){ 
 | 
            return new FebsResponse().fail().message("分类名称不能为空"); 
 | 
        } 
 | 
        List<MallGoodsCategory> categorys = mallGoodsCategoryMapper.selectCategoryByName(name); 
 | 
        if(CollUtil.isNotEmpty(categorys)){ 
 | 
            return new FebsResponse().fail().message("分类名称不能重复"); 
 | 
        } 
 | 
  
 | 
        MallGoodsCategory goodsCategory = new MallGoodsCategory(); 
 | 
        goodsCategory.setName(name); 
 | 
        if(ObjectUtil.isNotEmpty(mallGoodsCategory.getParentId())){ 
 | 
            Long parentId = mallGoodsCategory.getParentId(); 
 | 
            MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); 
 | 
            goodsCategory.setParentId(mallGoodsCategory.getParentId()); 
 | 
//            goodsCategory.setParentIds(mallGoodsCategoryParent.getParentIds()+mallGoodsCategory.getParentId()+","); 
 | 
        } 
 | 
        mallGoodsCategoryMapper.insert(goodsCategory); 
 | 
        return new FebsResponse().success(); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public List<MallGoodsCategory> getCategorys(MallGoodsCategory mallGoodsCategory) { 
 | 
        List<MallGoodsCategory> mallGoodsCategorys = mallGoodsCategoryMapper.getCategorys(); 
 | 
        return mallGoodsCategorys; 
 | 
    } 
 | 
  
 | 
} 
 |