package com.bocloud.ims.repository.resource;

import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.BasicGenericDao;
import com.bocloud.ims.entity.resource.YumRepo;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository("yumRepoRepository")
public class YumRepoRepository extends BasicGenericDao<YumRepo, Long> {

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

	public List<YumRepo> list() throws Exception {
		String sql = "select a.*,b.name as image_name, b.os_version, b.os_type, b.iso_name from yum_repo a left join image b on a.image_id = b.id";
		return this.list(YumRepo.class, sql);
	}

	public YumRepo query(String name) throws Exception {
		String sql = "select a.*,b.name as image_name, b.os_version, b.os_type, b.iso_name " + "from yum_repo a "
				+ "         left join image b on a.image_id = b.id " + "where 1 = 1 and a.name = :name";
		Map<String, Object> paramMap = MapTools.simpleMap("name", name);
		List<YumRepo> list = this.list(YumRepo.class, sql,paramMap);
		return list.isEmpty() ? null : list.get(0);
	}
}
