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

import com.xisc.pm.domain.entity.PmSteelCastSlab;
import com.xisc.pm.domain.repository.PmSteelCastSlabRepository;
import com.xisc.pm.infra.mapper.PmSteelCastSlabMapper;
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;

/**
 * 炼钢连铸制造命令板坯表(PmSteelCastSlab)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-15 10:21:18
 */
@Component
public class PmSteelCastSlabRepositoryImpl extends BaseRepositoryImpl<PmSteelCastSlab> implements PmSteelCastSlabRepository {
    @Resource
    private PmSteelCastSlabMapper pmSteelCastSlabMapper;

    @Override
    public List<PmSteelCastSlab> selectList(PmSteelCastSlab pmSteelCastSlab) {
        return pmSteelCastSlabMapper.selectList(pmSteelCastSlab);
    }

    @Override
    public PmSteelCastSlab selectByPrimary(Long steelCastSlabId) {
        PmSteelCastSlab pmSteelCastSlab = new PmSteelCastSlab();
        pmSteelCastSlab.setSteelCastSlabId(steelCastSlabId);
        List<PmSteelCastSlab> pmSteelCastSlabs = pmSteelCastSlabMapper.selectList(pmSteelCastSlab);
        if (CollectionUtils.isEmpty(pmSteelCastSlabs)) {
            return null;
        }
        return pmSteelCastSlabs.get(0);
    }

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

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