use of com.baomidou.dynamic.datasource.annotation.DS in project longmarch by yuyueqty.
the class SysTableBodyServiceImpl method getDataPage.
@DS("master")
@Override
public Map<String, Object> getDataPage(String code, String dataSource, Map<String, Object> params) {
SysTableBody sysTableBody = getSysTableBody(code);
Map<String, Object> result = buildResult(sysTableBody);
Map<String, Object> newParams = PageFactory.buildMap(dataSource, params);
String cacheKey = getCacheKey(STATISTICS, sysTableBody.getCode(), newParams.toString());
Object data = CacheUtil.get(cacheKey);
if (data != null && IS_CACHE) {
result.put("data", data);
} else {
Page<LinkedHashMap<String, Object>> page;
try {
switchingDataSource(dataSource, sysTableBody.getDataSource());
page = sysAutoMapper.page(PageFactory.getInstance(newParams), newParams, sysTableBody.getSqlText());
CacheUtil.put(cacheKey, page, TIME_OUT);
} catch (PersistenceException e) {
throw new PersistenceException(e.getMessage());
}
result.put("data", page);
}
return result;
}
use of com.baomidou.dynamic.datasource.annotation.DS in project longmarch by yuyueqty.
the class SysTableBodyServiceImpl method getDataList.
@DS("master")
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> getDataList(String code, List<String> dataSources, Map<String, Object> params) {
SysTableBody sysTableBody = getSysTableBody(code);
Map<String, Object> result = buildResult(sysTableBody);
List<LinkedHashMap<String, Object>> dataList = new ArrayList<>();
for (String dataSource : dataSources) {
Map<String, Object> newParams = PageFactory.buildMap(dataSource, params);
String cacheKey = getCacheKey(STATISTICS_EXPORT, code, newParams.toString());
Object object = CacheUtil.get(cacheKey);
if (object != null && IS_CACHE) {
dataList.addAll((Collection<? extends LinkedHashMap<String, Object>>) object);
} else {
try {
switchingDataSource(dataSource, sysTableBody.getDataSource());
List<LinkedHashMap<String, Object>> mapList = sysAutoMapper.list(newParams, sysTableBody.getSqlText());
if (mapList != null && mapList.size() > 0) {
dataList.addAll(mapList);
CacheUtil.put(cacheKey, mapList, TIME_OUT);
}
} catch (Exception ignored) {
// TODO do nothing
}
}
}
result.put("data", dataList);
return result;
}
Aggregations