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

import com.xisc.pm.domain.entity.PmSteelCastLot;
import com.xisc.pm.domain.repository.PmSteelCastLotRepository;
import com.xisc.pm.infra.mapper.PmSteelCastLotMapper;
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;

/**
 * 炼钢连铸制造命令LOT表(PmSteelCastLot)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-16 08:25:59
 */
@Component
public class PmSteelCastLotRepositoryImpl extends BaseRepositoryImpl<PmSteelCastLot> implements PmSteelCastLotRepository {
    @Resource
    private PmSteelCastLotMapper pmSteelCastLotMapper;

    @Override
    public List<PmSteelCastLot> selectList(PmSteelCastLot pmSteelCastLot) {
        return pmSteelCastLotMapper.selectList(pmSteelCastLot);
    }

    @Override
    public PmSteelCastLot selectByPrimary(Long steelCastLotId) {
        PmSteelCastLot pmSteelCastLot = new PmSteelCastLot();
        pmSteelCastLot.setSteelCastLotId(steelCastLotId);
        List<PmSteelCastLot> pmSteelCastLots = pmSteelCastLotMapper.selectList(pmSteelCastLot);
        if (CollectionUtils.isEmpty(pmSteelCastLots)) {
            return null;
        }
        return pmSteelCastLots.get(0);
    }

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