package com.bocloud.ims.repository.resource;

import com.bocloud.database.core.intf.impl.JdbcGenericDao;
import com.bocloud.ims.entity.resource.SanFabricZoneMember;
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;

/**
 * @author luyanchao
 * @since 2019/2/22 14:57
 */
@Repository("sanFabricZoneMemberRepository")
public class SanFabricZoneMemberRepository extends JdbcGenericDao<SanFabricZoneMember, Long> {

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

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

    public void removeByZone(long zoneId) {
        String sql = "update san_fabric_zone_member set is_deleted = 1 where zone_id = :zoneId ";
        Map<String, Object> params = new HashMap<>(8);
        params.put("zoneId", zoneId);
        execute(sql, params);
    }

    public List<SanFabricZoneMember> listByZone(long zoneId) {
        String sql = "select a.* from san_fabric_zone_member a where is_deleted = 0 and zone_id = :zoneId ";
        Map<String, Object> params = new HashMap<>(8);
        params.put("zoneId", zoneId);
        return this.list(SanFabricZoneMember.class, sql, params);
    }

    public SanFabricZoneMember get(long id) {
        String sql = "select a.* from san_fabric_zone_member a where a.id = :id ";
        Map<String, Object> params = new HashMap<>(8);
        params.put("id", id);
        List<SanFabricZoneMember> list = this.list(SanFabricZoneMember.class, sql, params);
        return list == null || list.size() == 0 ? null : list.get(0);
    }
}
