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

import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.BasicGenericDao;
import com.bocloud.ims.entity.resource.horizon.VmwareHorizonVcenterRelation;
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;

/**
 * Horizon-vcenter关系Repository接口实现
 * 
 * @author wangyu
 * @version 1.0
 * @since 2020年3月30日
 *
 */
@Repository("vmwareHorizonVcenterRelationRepository")
public class VmwareHorizonVcenterRelationRepository extends BasicGenericDao<VmwareHorizonVcenterRelation, Long> {

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

	public VmwareHorizonVcenterRelation query(Long id) throws Exception {
		String sql = "select * from vmware_horizon_vcenter_relation a where a.id = :id";
		Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
		List<VmwareHorizonVcenterRelation> list = this.list(VmwareHorizonVcenterRelation.class, sql, params);
		return list.isEmpty() ? null : list.get(0);
	}

	public List<VmwareHorizonVcenterRelation> listByHorizonVendorId(Long horizonVendorId) throws Exception {
		String sql = "select * from vmware_horizon_vcenter_relation a where a.horizon_vendor_id = :horizonVendorId";
		Map<String, Object> params = MapTools.simpleMap("horizonVendorId", horizonVendorId);
		return this.list(VmwareHorizonVcenterRelation.class, sql, params);
	}

	public boolean removeByHorizonVendorId(Long horizonVendorId) throws Exception {
		String sql = "delete from vmware_horizon_vcenter_relation where horizon_vendor_id = :horizonVendorId";
		Map<String, Object> params = MapTools.simpleMap("horizonVendorId", horizonVendorId);
		return this.execute(sql, params) > 0;
	}

	public List<VmwareHorizonVcenterRelation> listByVcenterVendorId(Long vcenterVendorId) throws Exception {
		String sql = "select * from vmware_horizon_vcenter_relation a where a.vcenter_vendor_id = :vcenterVendorId";
		Map<String, Object> params = MapTools.simpleMap("vcenterVendorId", vcenterVendorId);
		return this.list(VmwareHorizonVcenterRelation.class, sql, params);
	}

	public boolean removeByVcenterVendorId(Long vcenterVendorId) throws Exception {
		String sql = "delete from vmware_horizon_vcenter_relation where vcenter_vendor_id = :vcenterVendorId";
		Map<String, Object> params = MapTools.simpleMap("vcenterVendorId", vcenterVendorId);
		return this.execute(sql, params) > 0;
	}

}
