|
|
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
+import com.roma.romaapi.facade.MultipleDb;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -16,6 +17,8 @@ public class DbApiDao {
|
|
|
|
|
|
@Autowired
|
|
|
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
+ @Autowired
|
|
|
+ private MultipleDb multipleDb;
|
|
|
// 通过code,获取要执行的sql
|
|
|
public Map<String, Object> dbQueryForMap(String sqlCode) {
|
|
|
try {
|
|
|
@@ -33,16 +36,18 @@ public class DbApiDao {
|
|
|
}
|
|
|
|
|
|
// 获取sql总数,需要完整的sql和要绑定的参数
|
|
|
- public Integer dbCountQueryForObject(String sql, Map bindValue) {
|
|
|
- Integer count = namedParameterJdbcTemplate.queryForObject(sql, bindValue, Integer.class);
|
|
|
+ public Integer dbCountQueryForObject(String datasource, String sql, Map bindValue) {
|
|
|
+ NamedParameterJdbcTemplate execNamedParameterJdbcTemplate = multipleDb.getMultipleDatasourceByDbCode(datasource);
|
|
|
+ Integer count = execNamedParameterJdbcTemplate.queryForObject(sql, bindValue, Integer.class);
|
|
|
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
// 获取查询数据--单条数据使用
|
|
|
- public Map dbCustomQueryForMap(String sql, Map bindValue) {
|
|
|
+ public Map dbCustomQueryForMap(String datasource, String sql, Map bindValue) {
|
|
|
try {
|
|
|
- Map<String, Object> resMap2 = namedParameterJdbcTemplate.queryForMap(sql, bindValue);
|
|
|
+ NamedParameterJdbcTemplate execNamedParameterJdbcTemplate = multipleDb.getMultipleDatasourceByDbCode(datasource);
|
|
|
+ Map<String, Object> resMap2 = execNamedParameterJdbcTemplate.queryForMap(sql, bindValue);
|
|
|
return resMap2;
|
|
|
} catch (EmptyResultDataAccessException e) {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
@@ -53,14 +58,16 @@ public class DbApiDao {
|
|
|
}
|
|
|
|
|
|
// 查询数据--多条数据使用
|
|
|
- public List<Map<String, Object>> dbCustomQueryForList(String sql, Map<String, Object> bindValue){
|
|
|
- List<Map<String, Object>> resMap2 = namedParameterJdbcTemplate.queryForList(sql, bindValue);
|
|
|
+ public List<Map<String, Object>> dbCustomQueryForList(String datasource, String sql, Map<String, Object> bindValue){
|
|
|
+ NamedParameterJdbcTemplate execNamedParameterJdbcTemplate = multipleDb.getMultipleDatasourceByDbCode(datasource);
|
|
|
+ List<Map<String, Object>> resMap2 = execNamedParameterJdbcTemplate.queryForList(sql, bindValue);
|
|
|
return resMap2;
|
|
|
}
|
|
|
|
|
|
// 执行增删改语句
|
|
|
- public Integer dbUpdate(String sql, Map<String, Object> bindValue){
|
|
|
- Integer row = namedParameterJdbcTemplate.update(sql, bindValue);
|
|
|
+ public Integer dbUpdate(String datasource, String sql, Map<String, Object> bindValue){
|
|
|
+ NamedParameterJdbcTemplate execNamedParameterJdbcTemplate = multipleDb.getMultipleDatasourceByDbCode(datasource);
|
|
|
+ Integer row = execNamedParameterJdbcTemplate.update(sql, bindValue);
|
|
|
return row;
|
|
|
}
|
|
|
}
|