package com.zzsmart.qomo.kn.cost.manage.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialBomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 物料bom 服务实现类
 * </p>
 *
 * @author
 * @since 2024-06-21
 */
@Service
public class CostMaterialBomServiceImpl extends ServiceImpl<CostMaterialBomMapper, CostMaterialBom> implements CostMaterialBomService {
    @Autowired
    CostMaterialBomMapper costMaterialBomMapper;

    /**
     * 分页查询
     *
     * @param materialNumber
     * @return
     */
    @Override
    public List<CostMaterialBom> queryListResult(String materialNumber) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (StrUtil.isNotEmpty(materialNumber)) {
            // 物料号
            queryWrapper.like("material_code", materialNumber);
        }
        List list = costMaterialBomMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 查询最顶层物料编号下所有的物料
     *
     * @param topMaterialCode
     * @return
     */
    @Override
    public List<CostMaterialBom> queryAllBomInfoBytopMaterialCode(String topMaterialCode) {
        QueryWrapper queryWrapper = new QueryWrapper();
        //TODO 循环遍历查出所有的物料下的物料（包含最上层的物料）
//        if (StrUtil.isNotEmpty(topMaterialCode)) {
//            // 物料号
//            queryWrapper.like("material_code", topMaterialCode);
//        }
        List list = costMaterialBomMapper.selectList(queryWrapper);
        return list;
    }
}
