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

import com.xisc.pm.domain.entity.PmSlabEstaPlan;
import com.xisc.pm.domain.repository.PmSlabEstaPlanRepository;
import com.xisc.pm.infra.mapper.PmSlabEstaPlanMapper;
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;

/**
 * 组炉编制表(PmSlabEstaPlan)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-09 16:31:17
 */
@Component
public class PmSlabEstaPlanRepositoryImpl extends BaseRepositoryImpl<PmSlabEstaPlan> implements PmSlabEstaPlanRepository {
    @Resource
    private PmSlabEstaPlanMapper pmSlabEstaPlanMapper;

    @Override
    public List<PmSlabEstaPlan> selectList(PmSlabEstaPlan pmSlabEstaPlan) {
        return pmSlabEstaPlanMapper.selectList(pmSlabEstaPlan);
    }

    @Override
    public PmSlabEstaPlan selectByPrimary(Long slabEstaPlanId) {
        PmSlabEstaPlan pmSlabEstaPlan = new PmSlabEstaPlan();
        pmSlabEstaPlan.setSlabEstaPlanId(slabEstaPlanId);
        List<PmSlabEstaPlan> pmSlabEstaPlans = pmSlabEstaPlanMapper.selectList(pmSlabEstaPlan);
        if (CollectionUtils.isEmpty(pmSlabEstaPlans)) {
            return null;
        }
        return pmSlabEstaPlans.get(0);
    }

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

    @Override
    public List<PmSlabEstaPlan> selectByPreCastLotNoList(Long tenantId, List<String> precCastLotNoList) {
        return  this.selectByCondition(Condition.builder(PmSlabEstaPlan.class)
                .andWhere(Sqls.custom().andEqualTo(PmSlabEstaPlan.FIELD_TENANT_ID, tenantId))
                .andWhere(Sqls.custom().andIn(PmSlabEstaPlan.FIELD_PREC_CAST_LOT_NO, precCastLotNoList))
                .build());
    }
}
