@ -7,6 +7,7 @@ import java.io.StringWriter;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.stream.Collectors ;
import java.util.zip.ZipEntry ;
import java.util.zip.ZipOutputStream ;
@ -38,7 +39,7 @@ import com.ruoyi.gen.util.VelocityUtils;
/ * *
* 业 务 服 务 层 实 现
*
*
* @author ruoyi
* /
@Service
@ -54,7 +55,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 查 询 业 务 信 息
*
*
* @param id 业 务 ID
* @return 业 务 信 息
* /
@ -68,7 +69,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 查 询 业 务 列 表
*
*
* @param genTable 业 务 信 息
* @return 业 务 集 合
* /
@ -80,7 +81,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 查 询 据 库 列 表
*
*
* @param genTable 业 务 信 息
* @return 数 据 库 表 集 合
* /
@ -92,7 +93,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 查 询 据 库 列 表
*
*
* @param tableNames 表 名 称 组
* @return 数 据 库 表 集 合
* /
@ -104,7 +105,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 查 询 所 有 表 信 息
*
*
* @return 表 信 息 集 合
* /
@Override
@ -115,7 +116,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 修 改 业 务
*
*
* @param genTable 业 务 信 息
* @return 结 果
* /
@ -137,7 +138,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 删 除 业 务 对 象
*
*
* @param tableIds 需 要 删 除 的 数 据 ID
* @return 结 果
* /
@ -151,7 +152,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 导 入 表 结 构
*
*
* @param tableList 导 入 表 列 表
* /
@Override
@ -186,7 +187,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 预 览 代 码
*
*
* @param tableId 表 编 号
* @return 预 览 数 据 列 表
* /
@ -219,7 +220,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 生 成 代 码 ( 下 载 方 式 )
*
*
* @param tableName 表 名 称
* @return 数 据
* /
@ -235,7 +236,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 生 成 代 码 ( 自 定 义 路 径 )
*
*
* @param tableName 表 名 称
* /
@Override
@ -277,7 +278,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 同 步 数 据 库
*
*
* @param tableName 表 名 称
* /
@Override
@ -286,7 +287,6 @@ public class GenTableServiceImpl implements IGenTableService
{
GenTable table = genTableMapper . selectGenTableByName ( tableName ) ;
List < GenTableColumn > tableColumns = table . getColumns ( ) ;
List < String > tableColumnNames = tableColumns . stream ( ) . map ( GenTableColumn : : getColumnName ) . collect ( Collectors . toList ( ) ) ;
List < GenTableColumn > dbTableColumns = genTableColumnMapper . selectDbTableColumnsByName ( tableName ) ;
if ( StringUtils . isEmpty ( dbTableColumns ) )
@ -295,11 +295,20 @@ public class GenTableServiceImpl implements IGenTableService
}
List < String > dbTableColumnNames = dbTableColumns . stream ( ) . map ( GenTableColumn : : getColumnName ) . collect ( Collectors . toList ( ) ) ;
Map < String , GenTableColumn > tableColumnsMap = tableColumns . stream ( ) . collect ( Collectors . toMap ( GenTableColumn : : getColumnName , GenTableColumn - > GenTableColumn , ( key1 , key2 ) - > key2 ) ) ;
dbTableColumns . forEach ( column - > {
if ( ! tableColumnNames . contains ( column . getColumnName ( ) ) )
if ( ! equalColumInfo( tableColumnsMap , column ) )
{
GenUtils . initColumnField ( column , table ) ;
genTableColumnMapper . insertGenTableColumn ( column ) ;
GenTableColumn tableColumn = tableColumnsMap . get ( column . getColumnName ( ) ) ;
if ( tableColumn ! = null ) {
column . setColumnId ( tableColumn . getColumnId ( ) ) ;
genTableColumnMapper . updateGenTableColumn ( column ) ;
} else {
genTableColumnMapper . insertGenTableColumn ( column ) ;
}
}
} ) ;
@ -308,11 +317,32 @@ public class GenTableServiceImpl implements IGenTableService
{
genTableColumnMapper . deleteGenTableColumns ( delColumns ) ;
}
}
/ * *
* 比 较 数 据 库 列 信 息
* @param tableColumnsMap
* @param column
* @return ture 数 据 库 字 段 信 息 与 information_schema 的 字 段 内 容 一 致 false 与 information_schema 的 字 段 内 容 不 一 致
* /
private boolean equalColumInfo ( Map < String , GenTableColumn > tableColumnsMap , GenTableColumn column ) {
String columnName = column . getColumnName ( ) ;
GenTableColumn tableColumns = tableColumnsMap . get ( columnName ) ;
if ( tableColumns = = null ) {
return false ;
}
return Objects . equals ( column . getColumnName ( ) , tableColumns . getColumnName ( ) ) & &
Objects . equals ( column . getColumnComment ( ) , tableColumns . getColumnComment ( ) ) & &
Objects . equals ( column . getColumnType ( ) , tableColumns . getColumnType ( ) ) & &
Objects . equals ( column . getSort ( ) , tableColumns . getSort ( ) ) & &
Objects . equals ( column . getIsPk ( ) , tableColumns . getIsPk ( ) ) & &
Objects . equals ( column . getIsIncrement ( ) , tableColumns . getIsIncrement ( ) ) ;
}
/ * *
* 批 量 生 成 代 码 ( 下 载 方 式 )
*
*
* @param tableNames 表 数 组
* @return 数 据
* /
@ -371,7 +401,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 修 改 保 存 参 数 校 验
*
*
* @param genTable 业 务 信 息
* /
@Override
@ -409,7 +439,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 设 置 主 键 列 信 息
*
*
* @param table 业 务 表 信 息
* /
public void setPkColumn ( GenTable table )
@ -444,7 +474,7 @@ public class GenTableServiceImpl implements IGenTableService
}
/ * *
* 设 置 主 子 表 信 息
*
*
* @param table 业 务 表 信 息
* /
public void setSubTable ( GenTable table )
@ -458,7 +488,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 设 置 代 码 生 成 其 他 选 项 值
*
*
* @param genTable 设 置 后 的 生 成 对 象
* /
public void setTableFromOptions ( GenTable genTable )
@ -471,7 +501,7 @@ public class GenTableServiceImpl implements IGenTableService
String treeName = paramsObj . getString ( GenConstants . TREE_NAME ) ;
String parentMenuId = paramsObj . getString ( GenConstants . PARENT_MENU_ID ) ;
String parentMenuName = paramsObj . getString ( GenConstants . PARENT_MENU_NAME ) ;
genTable . setTreeCode ( treeCode ) ;
genTable . setTreeParentCode ( treeParentCode ) ;
genTable . setTreeName ( treeName ) ;
@ -482,7 +512,7 @@ public class GenTableServiceImpl implements IGenTableService
/ * *
* 获 取 代 码 生 成 地 址
*
*
* @param table 业 务 表 信 息
* @param template 模 板 文 件 路 径
* @return 生 成 地 址