| | |
| | | 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; |
| | | import org.dromara.common.json.utils.JsonUtils; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | | import org.dromara.generator.constant.GenConstants; |
| | | import org.dromara.generator.domain.GenTable; |
| | | import org.dromara.generator.domain.GenTableColumn; |
| | |
| | | private final GenTableColumnMapper genTableColumnMapper; |
| | | private final IdentifierGenerator identifierGenerator; |
| | | |
| | | private static final String[] TABLE_IGNORE = new String[]{"sj_", "act_", "flw_", "gen_"}; |
| | | private static final String[] TABLE_IGNORE = new String[]{"sj_", "flow_", "gen_"}; |
| | | |
| | | /** |
| | | * 查询业务字段列表 |
| | |
| | | .like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName())) |
| | | .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment())) |
| | | .between(params.get("beginTime") != null && params.get("endTime") != null, |
| | | "create_time", params.get("beginTime"), params.get("endTime")); |
| | | "create_time", params.get("beginTime"), params.get("endTime")) |
| | | .orderByDesc("update_time"); |
| | | return wrapper; |
| | | } |
| | | |
| | |
| | | } |
| | | // 过滤并转换表格数据 |
| | | List<GenTable> tables = tablesMap.values().stream() |
| | | .filter(x -> !StringUtils.containsAnyIgnoreCase(x.getName(), TABLE_IGNORE)) |
| | | .filter(x -> !StringUtils.startWithAnyIgnoreCase(x.getName(), TABLE_IGNORE)) |
| | | .filter(x -> { |
| | | if (CollUtil.isEmpty(tableNames)) { |
| | | return true; |
| | | } |
| | | return !StringUtils.containsAnyIgnoreCase(x.getName(), tableArrays); |
| | | return !StringUtils.equalsAnyIgnoreCase(x.getName(), tableArrays); |
| | | }) |
| | | .filter(x -> { |
| | | boolean nameMatches = true; |
| | |
| | | GenTable gen = new GenTable(); |
| | | gen.setTableName(x.getName()); |
| | | gen.setTableComment(x.getComment()); |
| | | gen.setCreateTime(x.getCreateTime()); |
| | | // postgresql的表元数据没有创建时间这个东西(好奇葩) 只能new Date代替 |
| | | gen.setCreateTime(ObjectUtil.defaultIfNull(x.getCreateTime(), new Date())); |
| | | gen.setUpdateTime(x.getUpdateTime()); |
| | | return gen; |
| | | }).toList(); |
| | | }).sorted(Comparator.comparing(GenTable::getCreateTime).reversed()) |
| | | .toList(); |
| | | |
| | | IPage<GenTable> page = pageQuery.build(); |
| | | page.setTotal(tables.size()); |
| | |
| | | } |
| | | |
| | | List<Table<?>> tableList = tablesMap.values().stream() |
| | | .filter(x -> !StringUtils.containsAnyIgnoreCase(x.getName(), TABLE_IGNORE)) |
| | | .filter(x -> !StringUtils.startWithAnyIgnoreCase(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 -> { |
| | |
| | | @DSTransactional |
| | | @Override |
| | | public void importGenTable(List<GenTable> tableList, String dataName) { |
| | | Long operId = LoginHelper.getUserId(); |
| | | try { |
| | | for (GenTable table : tableList) { |
| | | String tableName = table.getTableName(); |
| | | GenUtils.initTable(table, operId); |
| | | GenUtils.initTable(table); |
| | | table.setDataName(dataName); |
| | | 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) { |
| | | @Override |
| | | public List<GenTableColumn> selectDbTableColumnsByName(String tableName, String dataName) { |
| | | Table<?> table = ServiceProxy.metadata().table(tableName); |
| | | if (Objects.isNull(table)) { |
| | | if (ObjectUtil.isNull(table)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | LinkedHashMap<String, Column> columns = table.getColumns(); |
| | |
| | | tableColumn.setIsPk(String.valueOf(column.isPrimaryKey())); |
| | | tableColumn.setColumnName(column.getName()); |
| | | tableColumn.setColumnComment(column.getComment()); |
| | | tableColumn.setColumnType(column.getTypeName().toLowerCase()); |
| | | tableColumn.setColumnType(column.getOriginType().toLowerCase()); |
| | | tableColumn.setSort(column.getPosition()); |
| | | tableColumn.setIsRequired(column.isNullable() == 0 ? "1" : "0"); |
| | | tableColumn.setIsIncrement(column.isAutoIncrement() == -1 ? "0" : "1"); |
| | |
| | | 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("同步数据失败,原表结构不存在"); |
| | | } |
| | |
| | | String treeCode = paramsObj.getStr(GenConstants.TREE_CODE); |
| | | String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE); |
| | | String treeName = paramsObj.getStr(GenConstants.TREE_NAME); |
| | | String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID); |
| | | Long parentMenuId = paramsObj.getLong(GenConstants.PARENT_MENU_ID); |
| | | String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME); |
| | | |
| | | genTable.setTreeCode(treeCode); |