| | |
| | | /** |
| | | * 业务 服务层实现 |
| | | * |
| | | * @author ruoyi |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | |
| | | String tableName = table.getTableName(); |
| | | GenUtils.initTable(table, operName); |
| | | int row = baseMapper.insert(table); |
| | | if (row > 0) { |
| | | // 保存列信息 |
| | | List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | List<GenTableColumn> saveColumns = new ArrayList<>(); |
| | | for (GenTableColumn column : genTableColumns) { |
| | | GenUtils.initColumnField(column, table); |
| | | saveColumns.add(column); |
| | | } |
| | | if (CollUtil.isNotEmpty(saveColumns)) { |
| | | genTableColumnMapper.insertAll(saveColumns); |
| | | } |
| | | } |
| | | if (row > 0) { |
| | | // 保存列信息 |
| | | List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| | | List<GenTableColumn> saveColumns = new ArrayList<>(); |
| | | for (GenTableColumn column : genTableColumns) { |
| | | GenUtils.initColumnField(column, table); |
| | | saveColumns.add(column); |
| | | } |
| | | if (CollUtil.isNotEmpty(saveColumns)) { |
| | | genTableColumnMapper.insertAll(saveColumns); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("导入失败:" + e.getMessage()); |
| | |
| | | StringWriter sw = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate(template, Constants.UTF8); |
| | | tpl.merge(context, sw); |
| | | try { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeUtf8String(sw.toString(), path); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); |
| | | } |
| | | try { |
| | | String path = getGenPath(table, template); |
| | | FileUtils.writeUtf8String(sw.toString(), path); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| | | |
| | | List<GenTableColumn> saveColumns = new ArrayList<>(); |
| | | dbTableColumns.forEach(column -> { |
| | | if (!tableColumnNames.contains(column.getColumnName())) { |
| | | GenUtils.initColumnField(column, table); |
| | | saveColumns.add(column); |
| | | } |
| | | }); |
| | | if (CollUtil.isNotEmpty(saveColumns)) { |
| | | genTableColumnMapper.insertAll(saveColumns); |
| | | } |
| | | List<GenTableColumn> saveColumns = new ArrayList<>(); |
| | | dbTableColumns.forEach(column -> { |
| | | if (!tableColumnNames.contains(column.getColumnName())) { |
| | | GenUtils.initColumnField(column, table); |
| | | saveColumns.add(column); |
| | | } |
| | | }); |
| | | if (CollUtil.isNotEmpty(saveColumns)) { |
| | | genTableColumnMapper.insertAll(saveColumns); |
| | | } |
| | | |
| | | List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(delColumns)) { |
| | |
| | | @Override |
| | | public void validateEdit(GenTable genTable) { |
| | | if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { |
| | | Map<String, Object> paramsObj = genTable.getParams(); |
| | | Map<String, Object> paramsObj = genTable.getParams(); |
| | | if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) { |
| | | throw new ServiceException("树编码字段不能为空"); |
| | | } else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) { |
| | |
| | | * @param genTable 设置后的生成对象 |
| | | */ |
| | | public void setTableFromOptions(GenTable genTable) { |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions()); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions()); |
| | | if (StringUtils.isNotNull(paramsObj)) { |
| | | String treeCode = Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)); |
| | | String treeParentCode = Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)); |
| | |
| | | /** |
| | | * 获取代码生成地址 |
| | | * |
| | | * @param table 业务表信息 |
| | | * @param table 业务表信息 |
| | | * @param template 模板文件路径 |
| | | * @return 生成地址 |
| | | */ |