疯狂的狮子li
2021-10-27 695cb6d76b838b1e4cb161bae335faa948dca12a
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
@@ -41,7 +41,7 @@
/**
 * 业务 服务层实现
 *
 * @author ruoyi
 * @author Lion Li
 */
@Slf4j
@Service
@@ -163,18 +163,18 @@
                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());
@@ -253,12 +253,12 @@
                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());
                }
            }
        }
    }
@@ -281,16 +281,16 @@
        }
        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)) {
@@ -359,7 +359,7 @@
    @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))) {
@@ -422,7 +422,7 @@
     * @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));
@@ -441,7 +441,7 @@
    /**
     * 获取代码生成地址
     *
     * @param table 业务表信息
     * @param table    业务表信息
     * @param template 模板文件路径
     * @return 生成地址
     */