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

import com.xisc.pm.domain.entity.PmPdPlate;
import com.xisc.pm.domain.repository.PmPdPlateRepository;
import com.xisc.pm.infra.mapper.PmPdPlateMapper;
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;

/**
 * 组板钢板表(PmPdPlate)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-31 16:31:09
 */
@Component
public class PmPdPlateRepositoryImpl extends BaseRepositoryImpl<PmPdPlate> implements PmPdPlateRepository {
    @Resource
    private PmPdPlateMapper pmPdPlateMapper;

    @Override
    public List<PmPdPlate> selectList(PmPdPlate pmPdPlate) {
        return pmPdPlateMapper.selectList(pmPdPlate);
    }

    @Override
    public PmPdPlate selectByPrimary(Long pdPlateId) {
        PmPdPlate pmPdPlate = new PmPdPlate();
        pmPdPlate.setPmPdPlateId(pdPlateId);
        List<PmPdPlate> pmPdPlates = pmPdPlateMapper.selectList(pmPdPlate);
        if (CollectionUtils.isEmpty(pmPdPlates)) {
            return null;
        }
        return pmPdPlates.get(0);
    }

    @Override
    public List<PmPdPlate> selectByPlateNoList(Long tenantId, List<String> plateNoList) {
        return this.selectByCondition(Condition.builder(PmPdPlate.class)
                .andWhere(Sqls.custom().andIn(PmPdPlate.FIELD_PLATE_NO, plateNoList))
                .andWhere(Sqls.custom().andEqualTo(PmPdPlate.FIELD_TENANT_ID, tenantId)).build());
    }
}
