修改同步数据库接口 修改字段注释信息,类型,排序同步
This commit is contained in:
parent
d04a93d75d
commit
60acd607a9
|
|
@ -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 生成地址
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper">
|
||||
|
||||
|
||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
|
|
@ -28,23 +28,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<sql id="selectGenTableColumnVo">
|
||||
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
|
||||
<include refid="selectGenTableColumnVo"/>
|
||||
where table_id = #{tableId}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
||||
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
|
||||
insert into gen_table_column (
|
||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||
|
|
@ -88,11 +88,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
||||
update gen_table_column
|
||||
<set>
|
||||
column_comment = #{columnComment},
|
||||
column_type = #{columnType},
|
||||
java_type = #{javaType},
|
||||
java_field = #{javaField},
|
||||
is_insert = #{isInsert},
|
||||
|
|
@ -111,17 +112,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</update>
|
||||
|
||||
<delete id="deleteGenTableColumnByIds" parameterType="Long">
|
||||
delete from gen_table_column where table_id in
|
||||
delete from gen_table_column where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
<delete id="deleteGenTableColumns">
|
||||
delete from gen_table_column where column_id in
|
||||
delete from gen_table_column where column_id in
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
#{item.columnId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue