package com.bocloud.ims.repository.resource;

import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.VolumeTypeZone;
import com.bocloud.ims.repository.resource.common.EnhancedBaseRepository;

@Repository("volumeTypeZoneRepository")
public class VolumeTypeZoneRepository extends EnhancedBaseRepository<VolumeTypeZone, Long> {

	public void remove(Long id) {
		String sql = "delete from volume_type_zone where id = :id";
		Map<String, Object> params = MapTools.simpleMap("id", id);
		this.update(sql, params);
	}

	public void removeByVolumeTypeId(Long volumeTypeId) {
		String sql = "delete from volume_type_zone where volume_type_id = :volumeTypeId";
		Map<String, Object> params = MapTools.simpleMap("volumeTypeId", volumeTypeId);
		this.update(sql, params);
	}

	public List<VolumeTypeZone> listByVolumeTypeId(Long volumeTypeId) {
		String sql = "select a.* from volume_type_zone a " + "where volume_type_id = :volumeTypeId";
		Map<String, Object> params = MapTools.simpleMap("volumeTypeId", volumeTypeId);
		return this.list(VolumeTypeZone.class, sql, params);
	}

	public VolumeTypeZone getByVolumeTypeIdAndZoneId(Long volumeTypeId, Long zoneId) {
		String sql = "select * from volume_type_zone where volume_type_id = :volumeTypeId and zone_id = :zoneId";
		Map<String, Object> params = MapTools.simpleMap("volumeTypeId", volumeTypeId);
		params.put("zoneId", zoneId);
		List<VolumeTypeZone> list = this.list(VolumeTypeZone.class, sql, params);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

}
