重构返回结果集

This commit is contained in:
Binlin B Wang 2022-07-18 20:44:00 +08:00
parent 762a057138
commit 59493751d6
3 changed files with 31 additions and 42 deletions

View File

@ -2,6 +2,7 @@ package com.ebts.generator.dao;
import com.ebts.generator.entity.RelColumn;
import com.ebts.generator.entity.RelTable;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@ -48,7 +49,7 @@ public interface RelDao {
* @param tableName
* @return
*/
List<Map<String,Object>> tableColumns(String tableName);
List<Map<String,Object>> tableColumns(@Param("tableName") String tableName);
/**
* 通过主表id查询子表信息

View File

@ -1,6 +1,6 @@
package com.ebts.generator.service;
import com.ebts.common.utils.ServerResult;
import com.ebts.common.core.entity.Result;
import com.ebts.generator.entity.RelColumn;
import com.ebts.generator.entity.RelTable;
@ -19,16 +19,16 @@ public interface RelService {
*
* @return
*/
ServerResult<List<Map<String, Object>>> tableInfos();
Result<List<Map<String, Object>>> tableInfos();
/**
* 获取到关联边字段信息
*
* @param tableName 关联表表名
* @param relId 关联关系id
* @param relId 关联关系id
* @return
*/
ServerResult<List<RelColumn>> relColumns(String tableName, Long relId);
Result<List<RelColumn>> relColumns(String tableName, Long relId);
/**
* 通过tableName获取到字段信息
@ -36,7 +36,7 @@ public interface RelService {
* @param tableName
* @return
*/
ServerResult<List<Map<String,Object>>> tableColumns(String tableName);
Result<List<Map<String,Object>>> tableColumns(String tableName);
/**
* 通过主表id查询子表信息
@ -44,6 +44,6 @@ public interface RelService {
* @param tableId
* @return
*/
ServerResult<List<RelTable>> relTableByTableId(Long tableId);
Result<List<RelTable>> relTableByTableId(Long tableId);
}

View File

@ -1,5 +1,6 @@
package com.ebts.generator.service.impl;
import com.ebts.common.core.entity.Result;
import com.ebts.common.exception.EbtsException;
import com.ebts.common.utils.ServerResult;
import com.ebts.generator.dao.RelDao;
@ -11,7 +12,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@ -24,7 +28,7 @@ import java.util.Map;
public class RelServiceImpl implements RelService {
private Logger logger = LoggerFactory.getLogger(RelServiceImpl.class);
@Autowired
@Resource
private RelDao relDao;
/**
@ -33,14 +37,10 @@ public class RelServiceImpl implements RelService {
* @return
*/
@Override
public ServerResult<List<Map<String, Object>>> tableInfos() {
try {
List<Map<String, Object>> dataMap = relDao.tableInfos();
return new ServerResult<>(dataMap);
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException("获取数据库表信息错误",e);
}
@Transactional(propagation = Propagation.SUPPORTS)
public Result<List<Map<String, Object>>> tableInfos() {
List<Map<String, Object>> dataMap = relDao.tableInfos();
return Result.ok(dataMap);
}
/**
@ -51,38 +51,26 @@ public class RelServiceImpl implements RelService {
* @return
*/
@Override
public ServerResult<List<RelColumn>> relColumns(String tableName, Long relId) {
try {
List<RelColumn> relColumns = relDao.selectTableColumn(tableName);
for (RelColumn relColumn : relColumns) {
RelUtil.initRelColumn(relColumn, relId);
}
return new ServerResult<>(relColumns);
} catch (RuntimeException e) {
logger.error(e.getMessage());
throw new EbtsException("获取关联边字段信息错误",e);
@Transactional(propagation = Propagation.SUPPORTS)
public Result<List<RelColumn>> relColumns(String tableName, Long relId) {
List<RelColumn> relColumns = relDao.selectTableColumn(tableName);
for (RelColumn relColumn : relColumns) {
RelUtil.initRelColumn(relColumn, relId);
}
return Result.ok(relColumns);
}
@Override
public ServerResult<List<Map<String, Object>>> tableColumns(String tableName) {
try {
List<Map<String,Object>> columns = relDao.tableColumns(tableName);
return new ServerResult<>(columns);
}catch (RuntimeException e){
logger.error(e.getMessage());
throw new EbtsException("获取字段信息错误",e);
}
@Transactional(propagation = Propagation.SUPPORTS)
public Result<List<Map<String, Object>>> tableColumns(String tableName) {
List<Map<String, Object>> columns = relDao.tableColumns(tableName);
return Result.ok(columns);
}
@Override
public ServerResult<List<RelTable>> relTableByTableId(Long tableId) {
try {
List<RelTable> relTables = relDao.relTableByTableId(tableId);
return new ServerResult<>(relTables);
}catch (RuntimeException e){
logger.error(e.getMessage());
throw new EbtsException("获取关联数据错误",e);
}
@Transactional(propagation = Propagation.SUPPORTS)
public Result<List<RelTable>> relTableByTableId(Long tableId) {
List<RelTable> relTables = relDao.relTableByTableId(tableId);
return Result.ok(relTables);
}
}