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

import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.hmc.HmcProfileIoslot;
import com.bocloud.ims.repository.resource.common.EnhancedBaseRepository;
import org.springframework.stereotype.Repository;

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

/**
 * hmcProfileDao接口实现
 * 
 * @author ShaolongTan
 *
 */
@Deprecated
@Repository("hmcProfileIoslotRepository")
public class HmcProfileIoslotRepository extends EnhancedBaseRepository<HmcProfileIoslot, Long> {

	public boolean deleteByPartitionId(Long partitionId) {
		String sql = "delete from hmc_profile_ioslot where profile_id in (select id from hmc_profile where partition_id = :partitionId)";
		Map<String, Object> params = MapTools.simpleMap("partitionId", partitionId);
		return this.update(sql, params) > 0;
	}
	
	public boolean deleteByProfileId(Long profileId) {
		String sql = "delete from hmc_profile_ioslot where profile_id = :profileId";
		Map<String, Object> params = MapTools.simpleMap("profileId", profileId);
		return this.update(sql, params) > 0;
	}
	
	public List<HmcProfileIoslot> queryByProfileId(Long profileId) {
		String sql = "select a.* from hmc_profile_ioslot a where a.profile_id = :profileId";
		Map<String, Object> param = MapTools.simpleMap("profileId", profileId);
		List<Object> list = this.queryForList(sql, param, HmcProfileIoslot.class);
		List<HmcProfileIoslot> ioslots = new ArrayList<>();
		for (Object obj : list) {
			ioslots.add((HmcProfileIoslot) obj);
		}
		return ioslots;
	}
}
