| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.Dict; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | |
| | | import org.apache.velocity.app.Velocity; |
| | | import org.dromara.common.core.constant.Constants; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.core.utils.file.FileUtils; |
| | |
| | | private final GenTableMapper baseMapper; |
| | | private final GenTableColumnMapper genTableColumnMapper; |
| | | private final IdentifierGenerator identifierGenerator; |
| | | |
| | | private static final String[] TABLE_IGNORE = new String[]{"sj_", "act_", "flw_", "gen_"}; |
| | | |
| | | /** |
| | | * 查询业务字段列表 |
| | |
| | | // 获取查询条件 |
| | | String tableName = genTable.getTableName(); |
| | | String tableComment = genTable.getTableComment(); |
| | | // 获取分页参数 |
| | | Integer pageNum = pageQuery.getPageNum(); |
| | | Integer pageSize = pageQuery.getPageSize(); |
| | | |
| | | LinkedHashMap<String, Table> tablesMap = ServiceProxy.metadata().tables(); |
| | | LinkedHashMap<String, Table<?>> tablesMap = ServiceProxy.metadata().tables(); |
| | | if (CollUtil.isEmpty(tablesMap)) { |
| | | return TableDataInfo.build(); |
| | | } |
| | | List<String> tableNames = baseMapper.selectTableNameList(genTable.getDataName()); |
| | | String[] tableArrays; |
| | | if (CollUtil.isNotEmpty(tableNames)) { |
| | | tableArrays = tableNames.toArray(new String[0]); |
| | | } else { |
| | | tableArrays = new String[0]; |
| | | } |
| | | // 过滤并转换表格数据 |
| | | List<GenTable> tables = tablesMap.values().stream() |
| | | .filter(x -> !StringUtils.containsAnyIgnoreCase(x.getName(), TABLE_IGNORE)) |
| | | .filter(x -> { |
| | | if (CollUtil.isEmpty(tableNames)) { |
| | | return true; |
| | | } |
| | | return !StringUtils.equalsAnyIgnoreCase(x.getName(), tableArrays); |
| | | }) |
| | | .filter(x -> { |
| | | boolean nameMatches = true; |
| | | boolean commentMatches = true; |
| | |
| | | return gen; |
| | | }).toList(); |
| | | |
| | | // 创建分页对象,并设置总记录数 |
| | | IPage<GenTable> page = new Page<>(pageNum, pageSize, tables.size()); |
| | | // 使用CollUtil进行分页,并设置分页记录 |
| | | page.setRecords(CollUtil.page(pageNum - 1, pageSize, tables)); |
| | | IPage<GenTable> page = pageQuery.build(); |
| | | page.setTotal(tables.size()); |
| | | // 手动分页 set数据 |
| | | page.setRecords(CollUtil.page((int) page.getCurrent() - 1, (int) page.getSize(), tables)); |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<GenTable> selectDbTableListByNames(String[] tableNames, String dataName) { |
| | | Set<String> tableNameSet = new HashSet<>(List.of(tableNames)); |
| | | LinkedHashMap<String, Table> tablesMap = ServiceProxy.metadata().tables(); |
| | | LinkedHashMap<String, Table<?>> tablesMap = ServiceProxy.metadata().tables(); |
| | | |
| | | if (CollUtil.isEmpty(tablesMap)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | List<Table> tableList = tablesMap.values().stream() |
| | | List<Table<?>> tableList = tablesMap.values().stream() |
| | | .filter(x -> !StringUtils.containsAnyIgnoreCase(x.getName(), TABLE_IGNORE)) |
| | | .filter(x -> tableNameSet.contains(x.getName())).toList(); |
| | | |
| | | if (ArrayUtil.isEmpty(tableList)) { |
| | | if (CollUtil.isEmpty(tableList)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return tableList.stream().map(x -> { |
| | |
| | | int row = baseMapper.insert(table); |
| | | if (row > 0) { |
| | | // 保存列信息 |
| | | List<GenTableColumn> genTableColumns = selectDbTableColumnsByName(tableName, dataName); |
| | | List<GenTableColumn> genTableColumns = SpringUtils.getAopProxy(this).selectDbTableColumnsByName(tableName, dataName); |
| | | List<GenTableColumn> saveColumns = new ArrayList<>(); |
| | | for (GenTableColumn column : genTableColumns) { |
| | | GenUtils.initColumnField(column, table); |
| | |
| | | * @return 列信息 |
| | | */ |
| | | @DS("#dataName") |
| | | private List<GenTableColumn> selectDbTableColumnsByName(String tableName, String dataName) { |
| | | LinkedHashMap<String, Column> columns = ServiceProxy.service().metadata().table(tableName).getColumns(); |
| | | @Override |
| | | public List<GenTableColumn> selectDbTableColumnsByName(String tableName, String dataName) { |
| | | LinkedHashMap<String, Column> columns = ServiceProxy.metadata().columns(tableName); |
| | | List<GenTableColumn> tableColumns = new ArrayList<>(); |
| | | columns.forEach((columnName, column) -> { |
| | | GenTableColumn tableColumn = new GenTableColumn(); |
| | |
| | | List<GenTableColumn> tableColumns = table.getColumns(); |
| | | Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName); |
| | | |
| | | List<GenTableColumn> dbTableColumns = selectDbTableColumnsByName(table.getTableName(), table.getDataName()); |
| | | List<GenTableColumn> dbTableColumns = SpringUtils.getAopProxy(this).selectDbTableColumnsByName(table.getTableName(), table.getDataName()); |
| | | if (CollUtil.isEmpty(dbTableColumns)) { |
| | | throw new ServiceException("同步数据失败,原表结构不存在"); |
| | | } |