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

import com.xisc.pm.domain.entity.PmPdSlabInfo;
import com.xisc.pm.domain.repository.PmPdSlabInfoRepository;
import com.xisc.pm.infra.mapper.PmPdSlabInfoMapper;
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;

/**
 * 板坯信息表(PmPdSlabInfo)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-12 14:59:21
 */
@Component
public class PmPdSlabInfoRepositoryImpl extends BaseRepositoryImpl<PmPdSlabInfo> implements PmPdSlabInfoRepository {
    @Resource
    private PmPdSlabInfoMapper pmPdSlabInfoMapper;

    @Override
    public List<PmPdSlabInfo> selectList(PmPdSlabInfo pmPdSlabInfo) {
        return pmPdSlabInfoMapper.selectList(pmPdSlabInfo);
    }

    @Override
    public PmPdSlabInfo selectByPrimary(Long slabInfoId) {
        PmPdSlabInfo pmPdSlabInfo = new PmPdSlabInfo();
        pmPdSlabInfo.setPmPdSlabInfoId(slabInfoId);
        List<PmPdSlabInfo> pmPdSlabInfos = pmPdSlabInfoMapper.selectList(pmPdSlabInfo);
        if (CollectionUtils.isEmpty(pmPdSlabInfos)) {
            return null;
        }
        return pmPdSlabInfos.get(0);
    }

    @Override
    public PmPdSlabInfo selectBySlabNo(String slabNo, Long organizationId) {
        PmPdSlabInfo pmPdSlabInfo = new PmPdSlabInfo();
        pmPdSlabInfo.setTenantId(organizationId);
        pmPdSlabInfo.setSlabNo(slabNo);
        return this.selectOne(pmPdSlabInfo);
    }

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