Search in sources :

Example 1 with SysTableBody

use of top.longmarch.lmsys.entity.SysTableBody in project longmarch by yuyueqty.

the class SysTableBodyServiceImpl method show.

@Override
public List<SysTableTitle> show(String code, Map<String, Object> params) {
    SysTableBody sysTableBody = getSysTableBody(code);
    Object dataSource = params.get("dataSource");
    if (dataSource == null) {
        throw new BusinessException(5000, "数据源不能为空");
    }
    String id = String.valueOf(params.get("id"));
    if (StrUtil.isBlank(id)) {
        throw new BusinessException(5000, "数据主键不能为空");
    }
    switchingDataSource(dataSource.toString(), sysTableBody.getDataSource());
    String tableName = sysTableBody.getTableName();
    if (StrUtil.isBlank(tableName)) {
        throw new BusinessException(5000, String.format("%s表名未设置", tableName));
    }
    List<SysTableTitle> titles = sysAutoMapper.columns(tableName);
    String sql = buildShowSql(titles, tableName, id);
    LinkedHashMap<String, Object> titleValueMap = sysAutoMapper.show(sql);
    List<String> strings = null;
    String updateField = sysTableBody.getUpdateField();
    if (StrUtil.isNotBlank(updateField)) {
        strings = Arrays.asList(updateField.split(","));
    }
    for (SysTableTitle title : titles) {
        Object value = titleValueMap.get(title.getField());
        title.setValue(value);
        if (strings != null && strings.size() > 0) {
            title.setIsEdit(strings.contains(title.getField()));
        }
    }
    return titles;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) BusinessException(top.longmarch.lmcore.exception.BusinessException) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle)

Example 2 with SysTableBody

use of top.longmarch.lmsys.entity.SysTableBody in project longmarch by yuyueqty.

the class SysTableBodyServiceImpl method exportData.

@DS("master")
@SuppressWarnings("unchecked")
@Override
public void exportData(String code, String dataSource, Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
    SysTableBody sysTableBody = getSysTableBody(code);
    List<SysTableTitle> sysTableTitles = sysTableTitleService.tableTitleList(sysTableBody.getId());
    if (CollectionUtil.isEmpty(sysTableTitles)) {
        throw new BusinessException(5000, "统计SQL未配置字段");
    }
    List<ExcelExportEntity> exportEntityList = sysTableTitles.stream().map(e -> new ExcelExportEntity(e.getLabel(), e.getField())).collect(Collectors.toList());
    Map<String, Object> newParams = PageFactory.buildMap(dataSource, params);
    String cacheKey = getCacheKey(STATISTICS_EXPORT, code, newParams.toString());
    Object data = CacheUtil.get(cacheKey);
    List<LinkedHashMap<String, Object>> mapList = null;
    if (data != null && IS_CACHE) {
        mapList = (List<LinkedHashMap<String, Object>>) data;
    } else {
        try {
            switchingDataSource(dataSource, sysTableBody.getDataSource());
            mapList = sysAutoMapper.list(newParams, sysTableBody.getSqlText());
            if (CollectionUtil.isNotEmpty(mapList)) {
                CacheUtil.put(cacheKey, mapList, TIME_OUT);
            }
        } catch (Exception ignored) {
        // TODO do nothing
        }
    }
    if (mapList != null && mapList.size() > 0) {
        ExportParams exportParams = new ExportParams(sysTableBody.getLabel(), sysTableBody.getLabel());
        exportParams.setType(ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntityList, mapList);
        DownLoadUtil.downLoad(response, request, workbook, sysTableBody.getCode());
    }
}
Also used : java.util(java.util) ExcelExportUtil(cn.afterturn.easypoi.excel.ExcelExportUtil) ExportParams(cn.afterturn.easypoi.excel.entity.ExportParams) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BusinessException(top.longmarch.lmcore.exception.BusinessException) PageFactory(top.longmarch.lmcore.common.PageFactory) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TableTitleDTO(top.longmarch.lmsys.dto.TableTitleDTO) SysAutoMapper(top.longmarch.lmsys.mapper.SysAutoMapper) DS(com.baomidou.dynamic.datasource.annotation.DS) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) DynamicRoutingDataSource(com.baomidou.dynamic.datasource.DynamicRoutingDataSource) DownLoadUtil(top.longmarch.lmcore.utils.upload.DownLoadUtil) Function(java.util.function.Function) ISysTableRelService(top.longmarch.lmsys.service.ISysTableRelService) MD5(cn.hutool.crypto.digest.MD5) JSONUtil(cn.hutool.json.JSONUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) Service(org.springframework.stereotype.Service) TableTitleVO(top.longmarch.lmsys.vo.TableTitleVO) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) ExcelExportEntity(cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity) CollectionUtil(cn.hutool.core.collection.CollectionUtil) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle) ISysTableTitleService(top.longmarch.lmsys.service.ISysTableTitleService) CacheUtil(top.longmarch.lmcore.cache.CacheUtil) ExcelType(cn.afterturn.easypoi.excel.entity.enmus.ExcelType) HttpServletResponse(javax.servlet.http.HttpServletResponse) ISysTableBodyService(top.longmarch.lmsys.service.ISysTableBodyService) Collectors(java.util.stream.Collectors) SearchSuper(top.longmarch.lmcore.common.SearchSuper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) Workbook(org.apache.poi.ss.usermodel.Workbook) DynamicDataSourceContextHolder(com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder) SysTableRel(top.longmarch.lmsys.entity.SysTableRel) SysTableBodyMapper(top.longmarch.lmsys.mapper.SysTableBodyMapper) Data(lombok.Data) JSONArray(cn.hutool.json.JSONArray) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SysTableBody(top.longmarch.lmsys.entity.SysTableBody) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle) ExcelExportEntity(cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BusinessException(top.longmarch.lmcore.exception.BusinessException) Workbook(org.apache.poi.ss.usermodel.Workbook) SysTableBody(top.longmarch.lmsys.entity.SysTableBody) ExportParams(cn.afterturn.easypoi.excel.entity.ExportParams) BusinessException(top.longmarch.lmcore.exception.BusinessException) DS(com.baomidou.dynamic.datasource.annotation.DS)

Example 3 with SysTableBody

use of top.longmarch.lmsys.entity.SysTableBody in project longmarch by yuyueqty.

the class SysAutoServiceImpl method details.

@Override
public List<SysTableTitle> details(String code, Map<String, Object> params) {
    SysTableBody sysTableBody = sysTableBodyService.getSysTableBodyByCode(code);
    AutoObject autoObject = new AutoObject(params, sysTableBody);
    switchingDataSource(autoObject.getDataSource(), sysTableBody.getDataSource());
    String tableName = sysTableBody.getTableName();
    if (StrUtil.isBlank(tableName)) {
        throw new BusinessException(5000, String.format("%s表名未设置", tableName));
    }
    List<SysTableTitle> sysTableTitleList = sysAutoMapper.columns(tableName);
    String sql = buildShowSql(sysTableTitleList, tableName, autoObject.getId());
    LinkedHashMap<String, Object> titleValueMap = sysAutoMapper.show(sql);
    for (SysTableTitle title : sysTableTitleList) {
        Object value = titleValueMap.get(title.getField());
        title.setValue(value);
    }
    return sysTableTitleList;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) BusinessException(top.longmarch.lmcore.exception.BusinessException) SysTableTitle(top.longmarch.lmsys.entity.SysTableTitle)

Example 4 with SysTableBody

use of top.longmarch.lmsys.entity.SysTableBody in project longmarch by yuyueqty.

the class SysTableBodyServiceImpl method removeObjs.

@Override
public Boolean removeObjs(String code, Map<String, Object> params) {
    SysTableBody sysTableBody = getSysTableBody(code);
    UpdateObject updateObject = new UpdateObject(params);
    switchingDataSource(updateObject.getDataSource(), sysTableBody.getDataSource());
    String tableName = sysTableBody.getTableName();
    if (StrUtil.isBlank(tableName)) {
        throw new BusinessException(5000, String.format("%s表名未设置", tableName));
    }
    String sql = buildUpdateSql(tableName, "is_deleted = 1", updateObject.getId());
    if (sysAutoMapper.doSql(sql) > 0) {
        Map<String, Object> newParams = PageFactory.buildMap(updateObject.getDataSource(), params);
        String cacheKey = getCacheKey(STATISTICS, sysTableBody.getCode(), newParams.toString());
        CacheUtil.remove(cacheKey);
        return true;
    }
    return false;
}
Also used : SysTableBody(top.longmarch.lmsys.entity.SysTableBody) BusinessException(top.longmarch.lmcore.exception.BusinessException)

Example 5 with SysTableBody

use of top.longmarch.lmsys.entity.SysTableBody 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)

Aggregations

SysTableBody (top.longmarch.lmsys.entity.SysTableBody)7 BusinessException (top.longmarch.lmcore.exception.BusinessException)5 SysTableTitle (top.longmarch.lmsys.entity.SysTableTitle)4 DS (com.baomidou.dynamic.datasource.annotation.DS)3 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 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 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1