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

import com.xisc.pm.domain.entity.PmPdConstBt;
import com.xisc.pm.domain.repository.PmPdConstBtRepository;
import com.xisc.pm.infra.mapper.PmPdConstBtMapper;
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;

/**
 * 组板常数基准表(PmPdConstBt)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 09:08:20
 */
@Component
public class PmPdConstBtRepositoryImpl extends BaseRepositoryImpl<PmPdConstBt> implements PmPdConstBtRepository {
    @Resource
    private PmPdConstBtMapper pmPdConstBtMapper;

    @Override
    public List<PmPdConstBt> selectList(PmPdConstBt pmPdConstBt) {
        return pmPdConstBtMapper.selectList(pmPdConstBt);
    }

    @Override
    public PmPdConstBt selectByPrimary(Long ppcbId) {
        PmPdConstBt pmPdConstBt = new PmPdConstBt();
        pmPdConstBt.setPpcbId(ppcbId);
        List<PmPdConstBt> pmPdConstBts = pmPdConstBtMapper.selectList(pmPdConstBt);
        if (CollectionUtils.isEmpty(pmPdConstBts)) {
            return null;
        }
        return pmPdConstBts.get(0);
    }

    @Override
    public List<PmPdConstBt> selectByRollLineNoList(List<String> rollLineNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmPdConstBt.class)
                .andWhere(Sqls.custom().andIn(PmPdConstBt.FIELD_ROLL_LINE_NO, rollLineNoList))
                .andWhere(Sqls.custom().andEqualTo(PmPdConstBt.FIELD_TENANT_ID, tenantId)).build());
    }
}
