Search in sources :

Example 11 with DS

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;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) DS(com.baomidou.dynamic.datasource.annotation.DS)

Example 12 with DS

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;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BusinessException(top.longmarch.lmcore.exception.BusinessException) DS(com.baomidou.dynamic.datasource.annotation.DS)

Aggregations

DS (com.baomidou.dynamic.datasource.annotation.DS)12 Transactional (org.springframework.transaction.annotation.Transactional)6 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 GlobalTransactional (io.seata.spring.annotation.GlobalTransactional)2 BusinessException (top.longmarch.lmcore.exception.BusinessException)2 SysTableBody (top.longmarch.lmsys.entity.SysTableBody)2 ExcelExportUtil (cn.afterturn.easypoi.excel.ExcelExportUtil)1 ExportParams (cn.afterturn.easypoi.excel.entity.ExportParams)1 ExcelType (cn.afterturn.easypoi.excel.entity.enmus.ExcelType)1 ExcelExportEntity (cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity)1 CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 MD5 (cn.hutool.crypto.digest.MD5)1 JSONArray (cn.hutool.json.JSONArray)1 JSONUtil (cn.hutool.json.JSONUtil)1 DynamicRoutingDataSource (com.baomidou.dynamic.datasource.DynamicRoutingDataSource)1 DynamicDataSourceContextHolder (com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder)1 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1