package com.bocloud.ims.repository.resource.hmc;

import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.JdbcGenericDao;
import com.bocloud.ims.entity.resource.hmc.HmcSystemSharedProcessorPool;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Deprecated
@Component("hmcSystemSharedProcessorPoolRepository")
public class HmcSystemSharedProcessorPoolRepository extends JdbcGenericDao<HmcSystemSharedProcessorPool, Long>{

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

    public List<HmcSystemSharedProcessorPool> listByServerId(Long serverId) {
        String sql = "select a.* from hmc_system_shared_processor_pool a where a.is_deleted = 0 and a.server_id = :serverId";
        Map<String, Object> params = MapTools.simpleMap("serverId", serverId);
        return this.list(HmcSystemSharedProcessorPool.class, sql, params);
    }

    public boolean remove(Long id, Long userId) {
        String sql = "update hmc_system_shared_processor_pool set is_deleted = true , gmt_modify = :gmtModify ,mender_id = :menderId where is_deleted = 0 and id = :id";
        Map<String, Object> params = MapTools.simpleMap("id", id);
        params.put("menderId", userId);
        params.put("gmtModify", new Date());
        return this.execute(sql, params) > 0;
    }

    public HmcSystemSharedProcessorPool getById(Long id) {
        String sql = "select a.* from hmc_system_shared_processor_pool a where a.is_deleted = 0 and  a.id = :id";
        Map<String, Object> params = MapTools.simpleMap("id", id);
        List<HmcSystemSharedProcessorPool> list = this.list(HmcSystemSharedProcessorPool.class, sql, params);
        return list == null || list.size() == 0 ? null : list.get(0);

    }

    public HmcSystemSharedProcessorPool getByHmcPoolId(Long hmcPoolId, Long serverId) {
        String sql = "select a.* from hmc_system_shared_processor_pool a where a.is_deleted = 0 and a.hmc_pool_id = :hmcPoolId and a.server_id = :serverId";
        Map<String, Object> params = MapTools.simpleMap("hmcPoolId", hmcPoolId);
        params.put("serverId", serverId);
        List<HmcSystemSharedProcessorPool> list = this.list(HmcSystemSharedProcessorPool.class, sql, params);
        return list == null || list.size() == 0 ? null : list.get(0);
    }
}
