package com.xisc.pm.infra.repository.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.stereotype.Component;

import com.xisc.pm.domain.entity.MmSlab;
import com.xisc.pm.domain.repository.MmSlabRepository;
import com.xisc.pm.infra.mapper.MmSlabMapper;

/**
 * 板坯主数据主表(MmSlab)资源库
 *
 * @author 蒋雨航 yuhang.jiang02@hand-china.com
 * @since 2024-08-15 08:52:43
 */
@Component
public class MmSlabRepositoryImpl extends BaseRepositoryImpl<MmSlab> implements MmSlabRepository {
    @Resource
    private MmSlabMapper mmSlabMapper;

    @Override
    public List<MmSlab> selectList(MmSlab mmSlab) {
        return mmSlabMapper.selectList(mmSlab);
    }

    @Override
    public MmSlab selectByPrimary(Long slabId) {
        MmSlab mmSlab = new MmSlab();
        mmSlab.setSlabId(slabId);
        List<MmSlab> mmSlabs = mmSlabMapper.selectList(mmSlab);
        if (CollectionUtils.isEmpty(mmSlabs)) {
            return null;
        }
        return mmSlabs.get(0);
    }

    @Override
    public List<MmSlab> surplusSlabList(MmSlab mmSlab) {
        return mmSlabMapper.surplusSlabList(mmSlab);
    }

    @Override
    public MmSlab selectBySlabNo(String slabNo, Long tenantId) {
        MmSlab mmSlab = new MmSlab();
        mmSlab.setTenantId(tenantId);
        mmSlab.setSlabNo(slabNo);
        List<MmSlab> mmSlabs = selectList(mmSlab);
        if(mmSlabs == null || mmSlabs.isEmpty()) {
            return null;
        }
        return mmSlabs.get(0);
    }
    
    @Override
    public MmSlab selectByPonoSlabNo(String ponoSlabNo, Long tenantId) {
        MmSlab mmSlab = new MmSlab();
        mmSlab.setTenantId(tenantId);
        mmSlab.setPonoSlab(ponoSlabNo);
        mmSlab.setRecSts("2");
        List<MmSlab> mmSlabs = selectList(mmSlab);
        if(mmSlabs == null || mmSlabs.isEmpty()) {
            return null;
        }
        return mmSlabs.get(0);
    }

}
