package cn.ezhizao.project.business.service.impl;

import cn.ezhizao.project.business.domain.BizCarrierCategory;
import cn.ezhizao.project.business.mapper.BizCarrierCategoryMapper;
import cn.ezhizao.project.business.service.IBizCarrierCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 设备档案Service业务层处理
 *
 * @author ezhizao
 * @date 2023-11-14
 */
@Service
public class BizCarrierCategoryServiceImpl extends ServiceImpl<BizCarrierCategoryMapper, BizCarrierCategory> implements IBizCarrierCategoryService
{
    @Resource
    private BizCarrierCategoryMapper bizCarrierCategoryMapper;

    /**
     * 物理删除
     * @param id 待删除的id
     * @return 删除结果
     */
    @Override
    public int physicalDelete(Long id){
        return bizCarrierCategoryMapper.physicalDelete(id);
    }

    /**
     * 递归获取子类别
     */
    @Override
    public void getChildren(List<BizCarrierCategory> list) {
        // 循环List
        for (BizCarrierCategory item : list) {
            QueryWrapper<BizCarrierCategory> queryWrapper = new QueryWrapper<>();
            // 获取所有一级类别
            queryWrapper.eq("deleted", 0)
                    .eq("parent_id", item.getId());
            // 获取子类别
            List<BizCarrierCategory> children = bizCarrierCategoryMapper.selectList(queryWrapper);
            if (children.size() > 0) {
                item.setChildren(children);
                getChildren(children);
            }
        }
    }
}
