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.AppSceneCostBomRelevancy;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostBomRelevancyMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostBomRelevancyService;
import com.zzsmart.qomo.kn.cost.manage.vo.BomTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: app_scene_cost_bom_relevancy
 * @Author: jeecg-boot
 * @Date: 2024-09-08
 * @Version: V1.0
 */
@Service
public class AppSceneCostBomRelevancyServiceImpl extends ServiceImpl<AppSceneCostBomRelevancyMapper, AppSceneCostBomRelevancy> implements IAppSceneCostBomRelevancyService {
    /**
     * 物料BOM信息
     */
    @Autowired
    AppSceneCostBomRelevancyMapper costMaterialBomMapper;


    /**
     * 分页查询
     *
     * @param materialNumber
     * @return
     */
    @Override
    public List<AppSceneCostBomRelevancy> 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<BomTreeVo> queryAllBomInfoByTopMaterialCode(String topMaterialCode,String werks) {
        List<BomTreeVo> childrens = costMaterialBomMapper.findChildrenByParentId(topMaterialCode,werks);
        //TODO 循环遍历查出所有的物料下的物料（包含最上层的物料）
        //TODO 所有的物料并进行层级排序
        return childrens;
    }
}
