
package com.bocloud.ims.repository.resource;

import com.bocloud.common.model.Param;
import com.bocloud.common.model.SimpleBean;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.BasicGenericDao;
import com.bocloud.ims.entity.resource.StorageAccessPathGateway;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * xsky target数据访问实现
 *
 * @author wangyu
 * @version 1.0
 * @since 2020年5月15日
 *
 */
@Repository("storageAccessPathGatewayRepository")
public class StorageAccessPathGatewayRepository extends BasicGenericDao<StorageAccessPathGateway, Long> {

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

	public List<StorageAccessPathGateway> list(int page, int rows, List<Param> params, Map<String, String> sorter)
			throws Exception {
		return null;
	}

	public List<SimpleBean> list(List<Param> params, Map<String, String> sorter) throws Exception {
		return null;
	}

	public List<StorageAccessPathGateway> listByVendorId(Long vendorId) throws Exception {
		String sql = "select * from storage_access_path_gateway a where a.is_deleted = 0 and a.vendor_id = :vendorId ";
		Map<String, Object> params = MapTools.simpleMap("vendorId", vendorId);
		return this.list(StorageAccessPathGateway.class, sql, params);
	}

	public List<StorageAccessPathGateway> listByAccessPathId(Long accessPathId) throws Exception {
		String sql = "select a.*, s.name as host_name from storage_access_path_gateway a "
				+ "left join server s on a.host_id = s.id " + "where a.access_path_id = :accessPathId and a.is_deleted = 0 ";
		Map<String, Object> params = MapTools.simpleMap("accessPathId", accessPathId);
		return this.list(StorageAccessPathGateway.class, sql, params);
	}

	public StorageAccessPathGateway getByServerId(Long serverId) throws Exception {
		String sql = "select * from storage_access_path_gateway a where a.is_deleted = 0 and a.host_id = :serverId";
		Map<String, Object> params = MapTools.simpleMap("serverId", serverId);
		List<StorageAccessPathGateway> list = this.list(StorageAccessPathGateway.class, sql, params);
		return list == null || list.size() == 0 ? null : list.get(0);
	}

	public StorageAccessPathGateway getByUuid(String uuid) throws Exception {
		String sql = "select * from storage_access_path_gateway a where a.is_deleted = 0 and a.uuid = :uuid";
		Map<String, Object> params = MapTools.simpleMap("uuid", uuid);
		List<StorageAccessPathGateway> list = this.list(StorageAccessPathGateway.class, sql, params);
		return list == null || list.size() == 0 ? null : list.get(0);
	}

	public void remove(Long id, Long userId) throws Exception {
		String sql = "update storage_access_path_gateway set is_deleted = 1 where id = :id ";
		Map<String, Object> params = new HashMap<>(8);
		params.put("id", id);
		execute(sql, params);
	}
}
