package com.bocloud.ims.repository.resource;

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.ServerAssets;
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("serverAssetsRepository")
public class ServerAssetsRepository extends BasicGenericDao<ServerAssets, Long> {

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

	public ServerAssets query(Long id) throws Exception {
		String sql = "select * from server_assets where id = :id";
		Map<String, Object> param = MapTools.simpleMap("id", id);
		List<ServerAssets> list = this.list(ServerAssets.class, sql, param);
		return ListTool.isEmpty(list) ? null : list.get(0);
	}

	public ServerAssets getBySid(Long serverId) throws Exception {
		String sql = "select * from server_assets where server_id = :serverId";
		Map<String, Object> param = MapTools.simpleMap("serverId", serverId);
		List<ServerAssets> list = this.list(ServerAssets.class, sql, param);
		return ListTool.isEmpty(list) ? null : list.get(0);
	}

	public Boolean removeBySid(Long serverId) throws Exception {
		String sql = "delete from server_assets where server_id = :serverId";
		Map<String, Object> param = MapTools.simpleMap("serverId", serverId);
		return this.execute(sql, param) > 0;
	}

}
