package com.bocloud.ims.repository.topology;

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

/**
 * RegularExpression Dao层实现类
 *
 * @author lyy
 * @Version 1.0
 * @since 2017年9月15日
 */
@Repository("regularExpressionRepository")
public class RegularExpressionRepository extends BasicGenericDao<RegularExpression, Long> {

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

    public List<RegularExpression> listall() throws Exception {
        String sql = "select a.* from ci_regular_expression a";
        List<RegularExpression> list = this.list(RegularExpression.class, sql, new HashMap<String, Object>(10));
        return list;
    }

    public RegularExpression query(Long id) throws Exception {
        String sql = "select * from ci_regular_expression a where a.id = :id";
        Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
        List<RegularExpression> regularExpression = this.list(RegularExpression.class, sql, params);
        if (regularExpression.isEmpty()) {
            return null;
        }
        return regularExpression.get(0);
    }

}
