package com.bocloud.ims.repository.common;

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.nsx.NsxVcenterRelation;
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;

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

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

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

	public List<NsxVcenterRelation> listByNsxVendorId(Long nsxVendorId) throws Exception {
		String sql = "select * from nsx_vcenter_relation a where a.nsx_vendor_id = :nsxVendorId";
		Map<String, Object> params = MapTools.simpleMap("nsxVendorId", nsxVendorId);
		return this.list(NsxVcenterRelation.class, sql, params);
	}

	public boolean removeByNsxVendorId(Long nsxVendorId) throws Exception {
		String sql = "delete from nsx_vcenter_relation where nsx_vendor_id = :nsxVendorId";
		Map<String, Object> params = MapTools.simpleMap("nsxVendorId", nsxVendorId);
		return this.execute(sql, params) > 0;
	}

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

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

}
