优化字段更新未同步

This commit is contained in:
RuoYi 2022-01-14 11:46:05 +08:00
parent 869dcf73f8
commit b1b82857ba
1 changed files with 17 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import java.io.StringWriter;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -286,7 +287,7 @@ public class GenTableServiceImpl implements IGenTableService
{ {
GenTable table = genTableMapper.selectGenTableByName(tableName); GenTable table = genTableMapper.selectGenTableByName(tableName);
List<GenTableColumn> tableColumns = table.getColumns(); List<GenTableColumn> tableColumns = table.getColumns();
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
if (StringUtils.isEmpty(dbTableColumns)) if (StringUtils.isEmpty(dbTableColumns))
@ -296,9 +297,20 @@ public class GenTableServiceImpl implements IGenTableService
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> { dbTableColumns.forEach(column -> {
if (!tableColumnNames.contains(column.getColumnName())) GenUtils.initColumnField(column, table);
if (tableColumnMap.containsKey(column.getColumnName()))
{
GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
column.setColumnId(prevColumn.getColumnId());
if (column.isList())
{
// 如果是列表继续保留字典类型
column.setDictType(prevColumn.getDictType());
}
genTableColumnMapper.updateGenTableColumn(column);
}
else
{ {
GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(column); genTableColumnMapper.insertGenTableColumn(column);
} }
}); });
@ -359,7 +371,7 @@ public class GenTableServiceImpl implements IGenTableService
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.write(sw.toString(), zip, Constants.UTF8);
IOUtils.closeQuietly(sw); IOUtils.closeQuietly(sw);
zip.flush(); zip.flush();
zip.closeEntry(); zip.closeEntry();
} }
catch (IOException e) catch (IOException e)
@ -472,7 +484,7 @@ public class GenTableServiceImpl implements IGenTableService
String treeName = paramsObj.getString(GenConstants.TREE_NAME); String treeName = paramsObj.getString(GenConstants.TREE_NAME);
String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
genTable.setTreeCode(treeCode); genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode); genTable.setTreeParentCode(treeParentCode);
genTable.setTreeName(treeName); genTable.setTreeName(treeName);