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

import com.xisc.pm.domain.entity.PmSlabMerge;
import com.xisc.pm.domain.repository.PmSlabMergeRepository;
import com.xisc.pm.infra.mapper.PmSlabMergeMapper;
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;

/**
 * 组炉板坯合并表(PmSlabMerge)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-04 15:13:40
 */
@Component
public class PmSlabMergeRepositoryImpl extends BaseRepositoryImpl<PmSlabMerge> implements PmSlabMergeRepository {
    @Resource
    private PmSlabMergeMapper pmSlabMergeMapper;

    @Override
    public List<PmSlabMerge> selectList(PmSlabMerge pmSlabMerge) {
        return pmSlabMergeMapper.selectList(pmSlabMerge);
    }

    @Override
    public PmSlabMerge selectByPrimary(Long id) {
        PmSlabMerge pmSlabMerge = new PmSlabMerge();
        pmSlabMerge.setId(id);
        List<PmSlabMerge> pmSlabMerges = pmSlabMergeMapper.selectList(pmSlabMerge);
        if (CollectionUtils.isEmpty(pmSlabMerges)) {
            return null;
        }
        return pmSlabMerges.get(0);
    }

    @Override
    public List<PmSlabMerge> selectByMerTmpSlabNoList(List<String> mergeTemSlabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSlabMerge.class)
                        .andWhere(Sqls.custom().andIn(PmSlabMerge.FIELD_TMP_PONO_SLAB_NO, mergeTemSlabNoList))
                        .andWhere(Sqls.custom().andEqualTo(PmSlabMerge.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmSlabMerge> selectByMergeSlabNoList(List<String> merVirtualSlabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSlabMerge.class)
                .andWhere(Sqls.custom().andIn(PmSlabMerge.FIELD_MERGE_SLAB_NO, merVirtualSlabNoList))
                .andWhere(Sqls.custom().andEqualTo(PmSlabMerge.FIELD_TENANT_ID, tenantId))
                .build());
    }

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

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