package com.bocloud.ims.repository.resource;

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

/**
 * 云平台统计记录数据访问实现
 * 
 * @author wangyu
 * @version 1.0
 * @since 2020年5月15日
 *
 */
@Repository("cloudVendorStatisticsRepository")
public class CloudVendorStatisticsRepository extends BasicGenericDao<CloudVendorStatistics, Long> {

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

	/**
	 * 查询云平台统计记录
	 *
	 * @param vendorId
	 * @return
	 * @throws Exception
	 */

	public CloudVendorStatistics queryByVendorId(Long vendorId) throws Exception {
		String sql = "select * from cloud_vendor_statistics where vendor_id = :vendorId";
		Map<String, Object> paramMap = MapTools.simpleMap(Common.VENDORID, vendorId);
		List<CloudVendorStatistics> statisticsList = this.list(CloudVendorStatistics.class, sql, paramMap);
		return ListTool.isEmpty(statisticsList) ? null : statisticsList.get(0);
	}

	/**
	 * 根据云平台id删除统计记录
	 *
	 * @param vendorId
	 * @return
	 * @throws Exception
	 */

	public Boolean deleteByVendorId(Long vendorId) throws Exception {
		String sql = "delete from cloud_vendor_statistics where vendor_id = :vendorId ";
		Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
		return this.execute(sql, params) > 0;
	}

}
