package com.bocloud.ims.repository.resource.hmc;

import com.bocloud.database.core.intf.impl.JdbcGenericDao;
import com.bocloud.ims.entity.resource.hmc.HmcPartitionProcessor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Deprecated
@Repository
public class HmcPartitionProcessorRepository extends JdbcGenericDao<HmcPartitionProcessor, Long> {

    public HmcPartitionProcessorRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate) {
        super(jdbcTemplate, npJdbcTemplate);
    }

    public HmcPartitionProcessor getByPartitionId(Long partitionId) {
        String sql = "select * from hmc_partition_processor where partition_id = :partitionId and is_deleted = 0  ";
        Map<String, Object> params = new HashMap<>();
        params.put("partitionId", partitionId);
        List<HmcPartitionProcessor> list = super.list(HmcPartitionProcessor.class, sql, params);
        return Optional.ofNullable(list).map(o -> o.stream().findFirst().orElse(null)).orElse(null);
    }
}
