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

import com.xisc.pm.domain.entity.PmCmdSlab;
import com.xisc.pm.domain.repository.PmCmdSlabRepository;
import com.xisc.pm.infra.mapper.PmCmdSlabMapper;
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;

/**
 * 命令板坯表(PmCmdSlab)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 10:24:07
 */
@Component
public class PmCmdSlabRepositoryImpl extends BaseRepositoryImpl<PmCmdSlab> implements PmCmdSlabRepository {
    @Resource
    private PmCmdSlabMapper pmCmdSlabMapper;

    @Override
    public List<PmCmdSlab> selectList(PmCmdSlab pmCmdSlab) {
        return pmCmdSlabMapper.selectList(pmCmdSlab);
    }

    @Override
    public PmCmdSlab selectByPrimary(Long pmCmdSlabId) {
        PmCmdSlab pmCmdSlab = new PmCmdSlab();
        pmCmdSlab.setPmCmdSlabId(pmCmdSlabId);
        List<PmCmdSlab> pmCmdSlabs = pmCmdSlabMapper.selectList(pmCmdSlab);
        if (CollectionUtils.isEmpty(pmCmdSlabs)) {
            return null;
        }
        return pmCmdSlabs.get(0);
    }

    @Override
    public PmCmdSlab selectByPonoSlabNo(String ponoSlabNo, Long tenantId) {
        PmCmdSlab pmCmdSlab = new PmCmdSlab();
        pmCmdSlab.setPonoSlabNo(ponoSlabNo);
        pmCmdSlab.setTenantId(tenantId);
        return this.selectOne(pmCmdSlab);
    }

    @Override
    public List<PmCmdSlab> selectByPonoSlabList(List<String> ponoSlabList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCmdSlab.class)
                        .andWhere(Sqls.custom().andIn(PmCmdSlab.FIELD_PONO_SLAB_NO, ponoSlabList))
                        .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId))
                .build());
    }

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

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

    @Override
    public List<PmCmdSlab> selectBySlabNoList(List<String> slabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId))
                .andWhere(Sqls.custom().andIn(PmCmdSlab.FIELD_SLAB_NO, slabNoList))
                .build());
    }
}
