重构返回结果集
This commit is contained in:
parent
762a057138
commit
59493751d6
|
|
@ -2,6 +2,7 @@ package com.ebts.generator.dao;
|
||||||
|
|
||||||
import com.ebts.generator.entity.RelColumn;
|
import com.ebts.generator.entity.RelColumn;
|
||||||
import com.ebts.generator.entity.RelTable;
|
import com.ebts.generator.entity.RelTable;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -48,7 +49,7 @@ public interface RelDao {
|
||||||
* @param tableName
|
* @param tableName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Map<String,Object>> tableColumns(String tableName);
|
List<Map<String,Object>> tableColumns(@Param("tableName") String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过主表id查询子表信息
|
* 通过主表id查询子表信息
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.ebts.generator.service;
|
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.RelColumn;
|
||||||
import com.ebts.generator.entity.RelTable;
|
import com.ebts.generator.entity.RelTable;
|
||||||
|
|
||||||
|
|
@ -19,16 +19,16 @@ public interface RelService {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<List<Map<String, Object>>> tableInfos();
|
Result<List<Map<String, Object>>> tableInfos();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取到关联边字段信息
|
* 获取到关联边字段信息
|
||||||
*
|
*
|
||||||
* @param tableName 关联表表名
|
* @param tableName 关联表表名
|
||||||
* @param relId 关联关系id
|
* @param relId 关联关系id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<List<RelColumn>> relColumns(String tableName, Long relId);
|
Result<List<RelColumn>> relColumns(String tableName, Long relId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过tableName获取到字段信息
|
* 通过tableName获取到字段信息
|
||||||
|
|
@ -36,7 +36,7 @@ public interface RelService {
|
||||||
* @param tableName
|
* @param tableName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<List<Map<String,Object>>> tableColumns(String tableName);
|
Result<List<Map<String,Object>>> tableColumns(String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过主表id查询子表信息
|
* 通过主表id查询子表信息
|
||||||
|
|
@ -44,6 +44,6 @@ public interface RelService {
|
||||||
* @param tableId
|
* @param tableId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResult<List<RelTable>> relTableByTableId(Long tableId);
|
Result<List<RelTable>> relTableByTableId(Long tableId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ebts.generator.service.impl;
|
package com.ebts.generator.service.impl;
|
||||||
|
|
||||||
|
import com.ebts.common.core.entity.Result;
|
||||||
import com.ebts.common.exception.EbtsException;
|
import com.ebts.common.exception.EbtsException;
|
||||||
import com.ebts.common.utils.ServerResult;
|
import com.ebts.common.utils.ServerResult;
|
||||||
import com.ebts.generator.dao.RelDao;
|
import com.ebts.generator.dao.RelDao;
|
||||||
|
|
@ -11,7 +12,10 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -24,7 +28,7 @@ import java.util.Map;
|
||||||
public class RelServiceImpl implements RelService {
|
public class RelServiceImpl implements RelService {
|
||||||
private Logger logger = LoggerFactory.getLogger(RelServiceImpl.class);
|
private Logger logger = LoggerFactory.getLogger(RelServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private RelDao relDao;
|
private RelDao relDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,14 +37,10 @@ public class RelServiceImpl implements RelService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<List<Map<String, Object>>> tableInfos() {
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
try {
|
public Result<List<Map<String, Object>>> tableInfos() {
|
||||||
List<Map<String, Object>> dataMap = relDao.tableInfos();
|
List<Map<String, Object>> dataMap = relDao.tableInfos();
|
||||||
return new ServerResult<>(dataMap);
|
return Result.ok(dataMap);
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException("获取数据库表信息错误",e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,38 +51,26 @@ public class RelServiceImpl implements RelService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<List<RelColumn>> relColumns(String tableName, Long relId) {
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
try {
|
public Result<List<RelColumn>> relColumns(String tableName, Long relId) {
|
||||||
List<RelColumn> relColumns = relDao.selectTableColumn(tableName);
|
List<RelColumn> relColumns = relDao.selectTableColumn(tableName);
|
||||||
for (RelColumn relColumn : relColumns) {
|
for (RelColumn relColumn : relColumns) {
|
||||||
RelUtil.initRelColumn(relColumn, relId);
|
RelUtil.initRelColumn(relColumn, relId);
|
||||||
}
|
|
||||||
return new ServerResult<>(relColumns);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException("获取关联边字段信息错误",e);
|
|
||||||
}
|
}
|
||||||
|
return Result.ok(relColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<List<Map<String, Object>>> tableColumns(String tableName) {
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
try {
|
public Result<List<Map<String, Object>>> tableColumns(String tableName) {
|
||||||
List<Map<String,Object>> columns = relDao.tableColumns(tableName);
|
List<Map<String, Object>> columns = relDao.tableColumns(tableName);
|
||||||
return new ServerResult<>(columns);
|
return Result.ok(columns);
|
||||||
}catch (RuntimeException e){
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException("获取字段信息错误",e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<List<RelTable>> relTableByTableId(Long tableId) {
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
try {
|
public Result<List<RelTable>> relTableByTableId(Long tableId) {
|
||||||
List<RelTable> relTables = relDao.relTableByTableId(tableId);
|
List<RelTable> relTables = relDao.relTableByTableId(tableId);
|
||||||
return new ServerResult<>(relTables);
|
return Result.ok(relTables);
|
||||||
}catch (RuntimeException e){
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw new EbtsException("获取关联数据错误",e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue