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

import com.xisc.pm.domain.entity.PmSteelCastSlabItf;
import com.xisc.pm.domain.repository.PmSteelCastSlabItfRepository;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.mapper.PmSteelCastSlabItfMapper;
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;

/**
 * 炼钢连铸制造命令板坯-接口表(PmSteelCastSlabItf)资源库
 *
 * @author jie.yang04@hand-chian.com
 * @since 2024-10-15 10:30:28
 */
@Component
public class PmSteelCastSlabItfRepositoryImpl extends BaseRepositoryImpl<PmSteelCastSlabItf> implements PmSteelCastSlabItfRepository {
    @Resource
    private PmSteelCastSlabItfMapper pmSteelCastSlabItfMapper;

    @Override
    public List<PmSteelCastSlabItf> selectList(PmSteelCastSlabItf pmSteelCastSlabItf) {
        return pmSteelCastSlabItfMapper.selectList(pmSteelCastSlabItf);
    }

    @Override
    public PmSteelCastSlabItf selectByPrimary(Long itfId) {
        PmSteelCastSlabItf pmSteelCastSlabItf = new PmSteelCastSlabItf();
        pmSteelCastSlabItf.setItfId(itfId);
        List<PmSteelCastSlabItf> pmSteelCastSlabItfs = pmSteelCastSlabItfMapper.selectList(pmSteelCastSlabItf);
        if (CollectionUtils.isEmpty(pmSteelCastSlabItfs)) {
            return null;
        }
        return pmSteelCastSlabItfs.get(0);
    }

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

