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

import com.xisc.pm.domain.entity.PmSmallPltPos;
import com.xisc.pm.domain.repository.PmSmallPltPosRepository;
import com.xisc.pm.infra.mapper.PmSmallPltPosMapper;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.hzero.mybatis.domian.Condition;
import org.hzero.mybatis.util.Sqls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 组板小板位置表 资源库实现
 *
 * @author 曾俊 jun.zeng@hand-china.com 2024-08-02 08:02:39
 */
@Component
public class PmSmallPltPosRepositoryImpl extends BaseRepositoryImpl<PmSmallPltPos> implements PmSmallPltPosRepository {

    @Autowired
    private PmSmallPltPosMapper pmSmallPltPosMapper;

    @Override
    public List<PmSmallPltPos> selectByPdMatNo(Long tenantId, String virtualSlabNo) {
        PmSmallPltPos record = new PmSmallPltPos();
        record.setTenantId(tenantId);
        record.setPdMatNo(virtualSlabNo);
        return this.select(record);
    }

    @Override
    public int deleteByMatNo(Long tenantId, List<String> removePdMatNo) {
        return pmSmallPltPosMapper.deleteByMatNo(tenantId, removePdMatNo);
    }

    @Override
    public List<PmSmallPltPos> selectPmSmallPltPos(Long tenantId, List<String> virtualSlabNoList) {
        List<PmSmallPltPos> pmSmallPltPoss = this.selectByCondition(Condition.builder(PmSmallPltPos.class)
                .andWhere(Sqls.custom().andEqualTo(PmSmallPltPos.FIELD_TENANT_ID, tenantId)
                        .andIn(PmSmallPltPos.FIELD_PD_MAT_NO, virtualSlabNoList))
                .build());
        return pmSmallPltPoss;
    }

    @Override
    public List<PmSmallPltPos> selectByPdMatNoList(List<String> virtualNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSmallPltPos.class)
                .andWhere(Sqls.custom().andIn(PmSmallPltPos.FIELD_PD_MAT_NO, virtualNoList))
                .andWhere(Sqls.custom().andEqualTo(PmSmallPltPos.FIELD_TENANT_ID, tenantId)).build());
    }

    @Override
    public String selectMaxSmallDivNoBySlabNo(Long tenantId, String slabNo) {
        return pmSmallPltPosMapper.selectMaxSmallDivNoBySlabNo(tenantId , slabNo);
    }
}
