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

import com.xisc.pm.domain.entity.PmSteelCastHeatItf;
import com.xisc.pm.domain.repository.PmSteelCastHeatItfRepository;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.mapper.PmSteelCastHeatItfMapper;
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;

/**
 * 炼钢连铸制造命令炉次-接口表 (PmSteelCastHeatItf)资源库
 *
 * @author jie.yang04@hand-chian.com
 * @since 2024-10-15 10:29:56
 */
@Component
public class PmSteelCastHeatItfRepositoryImpl extends BaseRepositoryImpl<PmSteelCastHeatItf> implements PmSteelCastHeatItfRepository {
    @Resource
    private PmSteelCastHeatItfMapper pmSteelCastHeatItfMapper;

    @Override
    public List<PmSteelCastHeatItf> selectList(PmSteelCastHeatItf pmSteelCastHeatItf) {
        return pmSteelCastHeatItfMapper.selectList(pmSteelCastHeatItf);
    }

    @Override
    public PmSteelCastHeatItf selectByPrimary(Long itfId) {
        PmSteelCastHeatItf pmSteelCastHeatItf = new PmSteelCastHeatItf();
        pmSteelCastHeatItf.setItfId(itfId);
        List<PmSteelCastHeatItf> pmSteelCastHeatItfs = pmSteelCastHeatItfMapper.selectList(pmSteelCastHeatItf);
        if (CollectionUtils.isEmpty(pmSteelCastHeatItfs)) {
            return null;
        }
        return pmSteelCastHeatItfs.get(0);
    }

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

