package org.springblade.etl.service;

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

import org.springblade.etl.mapper.QueryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 服务实现类
 *
 * @author BladeX
 * @since 2021-03-20
 */
@Service
public class QueryService {
	
	@Autowired
	private QueryMapper baseMapper;

	@DS("#poolName")
	public List<Map<String, Object>> select(String poolName, String sql) {
		sql = sql.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&le;", "<=").replaceAll("&ge;", ">=");
		return baseMapper.selectList(sql);
	}

	@DS("#poolName")
	public List<Map<String, Object>> selectPageList(IPage<?> page, String poolName, String sql) {
		sql = sql.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&le;", "<=").replaceAll("&ge;", ">=");
		return baseMapper.selectPageList(page, sql);
	}
	
	@DS("#poolName")
	public IPage<Map<String, Object>> selectPage(IPage<?> page, String poolName, String sql){
		sql = sql.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&le;", "<=").replaceAll("&ge;", ">=");
		return baseMapper.selectPage(page, sql);
	}
	
	@DS("#poolName")
	public Map<String, Object> selectOne(String poolName, String sql){
		sql = sql.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&le;", "<=").replaceAll("&ge;", ">=");
		return baseMapper.selectOne(sql);
	}
	
//	@DS("#poolName")
//	public Integer selectCount(String poolName,String sql) {
//		sql = sql.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&le;", "<=").replaceAll("&ge;", ">=");
//		return baseMapper.selectCount(sql);
//	}

}
