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

import com.xisc.pm.domain.entity.PmSampleReserveBt;
import com.xisc.pm.domain.repository.PmSampleReserveBtRepository;
import com.xisc.pm.infra.mapper.PmSampleReserveBtMapper;
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;

/**
 * 预留试样基表(PmSampleReserveBt)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-12-18 15:13:05
 */
@Component
public class PmSampleReserveBtRepositoryImpl extends BaseRepositoryImpl<PmSampleReserveBt> implements PmSampleReserveBtRepository {
    @Resource
    private PmSampleReserveBtMapper pmSampleReserveBtMapper;

    @Override
    public List<PmSampleReserveBt> selectList(PmSampleReserveBt pmSampleReserveBt) {
        return pmSampleReserveBtMapper.selectList(pmSampleReserveBt);
    }

    @Override
    public PmSampleReserveBt selectByPrimary(Long psrbId) {
        PmSampleReserveBt pmSampleReserveBt = new PmSampleReserveBt();
        pmSampleReserveBt.setPsrbId(psrbId);
        List<PmSampleReserveBt> pmSampleReserveBts = pmSampleReserveBtMapper.selectList(pmSampleReserveBt);
        if (CollectionUtils.isEmpty(pmSampleReserveBts)) {
            return null;
        }
        return pmSampleReserveBts.get(0);
    }

    @Override
    public List<PmSampleReserveBt> selectByStNoList(List<String> stNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSampleReserveBt.class)
                        .andWhere(Sqls.custom().andIn(PmSampleReserveBt.FIELD_ST_NO, stNoList))
                        .andWhere(Sqls.custom().andEqualTo(PmSampleReserveBt.FIELD_TENANT_ID, tenantId))
                .build());
    }
}

