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

import com.xisc.pm.domain.entity.PmSteelCastHeat;
import com.xisc.pm.domain.repository.PmSteelCastHeatRepository;
import com.xisc.pm.infra.mapper.PmSteelCastHeatMapper;
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;

/**
 * 炼钢连铸制造命令炉次表 (PmSteelCastHeat)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-15 08:20:13
 */
@Component
public class PmSteelCastHeatRepositoryImpl extends BaseRepositoryImpl<PmSteelCastHeat> implements PmSteelCastHeatRepository {
    @Resource
    private PmSteelCastHeatMapper pmSteelCastHeatMapper;

    @Override
    public List<PmSteelCastHeat> selectList(PmSteelCastHeat pmSteelCastHeat) {
        return pmSteelCastHeatMapper.selectList(pmSteelCastHeat);
    }

    @Override
    public PmSteelCastHeat selectByPrimary(Long steelCastHeatId) {
        PmSteelCastHeat pmSteelCastHeat = new PmSteelCastHeat();
        pmSteelCastHeat.setSteelCastHeatId(steelCastHeatId);
        List<PmSteelCastHeat> pmSteelCastHeats = pmSteelCastHeatMapper.selectList(pmSteelCastHeat);
        if (CollectionUtils.isEmpty(pmSteelCastHeats)) {
            return null;
        }
        return pmSteelCastHeats.get(0);
    }

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

    @Override
    public List<PmSteelCastHeat> selectByCastLotNoList(List<String> castLotNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSteelCastHeat.class)
                .andWhere(Sqls.custom().andIn(PmSteelCastHeat.FIELD_CAST_LOT_NO, castLotNoList))
                .andWhere(Sqls.custom().andEqualTo(PmSteelCastHeat.FIELD_TENANT_ID, tenantId))
                .build());
    }
}
