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;
}
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());
}
}
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;
}
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;
}
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;
}
Aggregations