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

import com.xisc.pm.api.dto.PmPdCcSlabStoveParamDTO;
import com.xisc.pm.api.dto.PmPdCcSlabStoveResDTO;
import com.xisc.pm.domain.entity.PmPdCcSlab;
import com.xisc.pm.domain.repository.PmPdCcSlabRepository;
import com.xisc.pm.infra.mapper.PmPdCcSlabMapper;
import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.hzero.mybatis.domian.Condition;
import org.hzero.mybatis.util.Sqls;
import org.springframework.stereotype.Component;

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

/**
 * 组板连铸板坯表(PmPdCcSlab)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-31 16:36:58
 */
@Component
public class PmPdCcSlabRepositoryImpl extends BaseRepositoryImpl<PmPdCcSlab> implements PmPdCcSlabRepository {
    @Resource
    private PmPdCcSlabMapper pmPdCcSlabMapper;

    @Override
    public List<PmPdCcSlab> selectList(PmPdCcSlab pmPdCcSlab) {
        return pmPdCcSlabMapper.selectList(pmPdCcSlab);
    }

    @Override
    public PmPdCcSlab selectByPrimary(Long virtualSlabId) {
        PmPdCcSlab pmPdCcSlab = new PmPdCcSlab();
        pmPdCcSlab.setVirtualSlabId(virtualSlabId);
        List<PmPdCcSlab> pmPdCcSlabs = pmPdCcSlabMapper.selectList(pmPdCcSlab);
        if (CollectionUtils.isEmpty(pmPdCcSlabs)) {
            return null;
        }
        return pmPdCcSlabs.get(0);
    }

    @Override
    public List<PmPdCcSlabStoveResDTO> selectStoveList(PmPdCcSlabStoveParamDTO dto, Long tenantId, List<String> outSgNoList) {
        return pmPdCcSlabMapper.selectStoveList(dto, tenantId, outSgNoList);
    }
    
    @Override
    public PmPdCcSlab selectByPdMatNo(Long tenantId, String virtualSlabNo) {
        PmPdCcSlab record = new PmPdCcSlab();
        record.setVirtualSlabNo(virtualSlabNo);
        record.setTenantId(tenantId);
        return this.selectOne(record);
    }

    @Override
    public List<PmPdCcSlab> selectByVirtualSlabList(List<String> virtualSlabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmPdCcSlab.class)
                        .andWhere(Sqls.custom().andIn(PmPdCcSlab.FIELD_VIRTUAL_SLAB_NO, virtualSlabNoList))
                        .andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmPdCcSlab> selectByTmpSlabNoList(List<String> tmpSlabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmPdCcSlab.class)
                .andWhere(Sqls.custom().andIn(PmPdCcSlab.FIELD_TMP_SLAB_NO, tmpSlabNoList))
                .andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId))
                .build());
    }
}
