Pre Merge pull request !62 from Luozuanshi/master
This commit is contained in:
commit
17b6644553
|
|
@ -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.Objects;
|
||||||
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;
|
||||||
|
|
@ -38,7 +39,7 @@ import com.ruoyi.gen.util.VelocityUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务 服务层实现
|
* 业务 服务层实现
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -54,7 +55,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务信息
|
* 查询业务信息
|
||||||
*
|
*
|
||||||
* @param id 业务ID
|
* @param id 业务ID
|
||||||
* @return 业务信息
|
* @return 业务信息
|
||||||
*/
|
*/
|
||||||
|
|
@ -68,7 +69,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务列表
|
* 查询业务列表
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
* @return 业务集合
|
* @return 业务集合
|
||||||
*/
|
*/
|
||||||
|
|
@ -80,7 +81,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,7 +93,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
* @param tableNames 表名称组
|
* @param tableNames 表名称组
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,7 +105,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有表信息
|
* 查询所有表信息
|
||||||
*
|
*
|
||||||
* @return 表信息集合
|
* @return 表信息集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -115,7 +116,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改业务
|
* 修改业务
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
|
@ -137,7 +138,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除业务对象
|
* 删除业务对象
|
||||||
*
|
*
|
||||||
* @param tableIds 需要删除的数据ID
|
* @param tableIds 需要删除的数据ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
|
@ -151,7 +152,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入表结构
|
* 导入表结构
|
||||||
*
|
*
|
||||||
* @param tableList 导入表列表
|
* @param tableList 导入表列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -186,7 +187,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览代码
|
* 预览代码
|
||||||
*
|
*
|
||||||
* @param tableId 表编号
|
* @param tableId 表编号
|
||||||
* @return 预览数据列表
|
* @return 预览数据列表
|
||||||
*/
|
*/
|
||||||
|
|
@ -219,7 +220,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(下载方式)
|
* 生成代码(下载方式)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
|
|
@ -235,7 +236,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -277,7 +278,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -286,7 +287,6 @@ 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());
|
|
||||||
|
|
||||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||||
if (StringUtils.isEmpty(dbTableColumns))
|
if (StringUtils.isEmpty(dbTableColumns))
|
||||||
|
|
@ -295,11 +295,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());
|
||||||
|
|
||||||
|
Map<String, GenTableColumn> tableColumnsMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, GenTableColumn->GenTableColumn, (key1,key2)->key2));
|
||||||
|
|
||||||
dbTableColumns.forEach(column -> {
|
dbTableColumns.forEach(column -> {
|
||||||
if (!tableColumnNames.contains(column.getColumnName()))
|
if (!equalColumInfo(tableColumnsMap,column))
|
||||||
{
|
{
|
||||||
GenUtils.initColumnField(column, table);
|
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);
|
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 表数组
|
* @param tableNames 表数组
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
|
|
@ -371,7 +401,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存参数校验
|
* 修改保存参数校验
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -409,7 +439,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置主键列信息
|
* 设置主键列信息
|
||||||
*
|
*
|
||||||
* @param table 业务表信息
|
* @param table 业务表信息
|
||||||
*/
|
*/
|
||||||
public void setPkColumn(GenTable table)
|
public void setPkColumn(GenTable table)
|
||||||
|
|
@ -444,7 +474,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 设置主子表信息
|
* 设置主子表信息
|
||||||
*
|
*
|
||||||
* @param table 业务表信息
|
* @param table 业务表信息
|
||||||
*/
|
*/
|
||||||
public void setSubTable(GenTable table)
|
public void setSubTable(GenTable table)
|
||||||
|
|
@ -458,7 +488,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置代码生成其他选项值
|
* 设置代码生成其他选项值
|
||||||
*
|
*
|
||||||
* @param genTable 设置后的生成对象
|
* @param genTable 设置后的生成对象
|
||||||
*/
|
*/
|
||||||
public void setTableFromOptions(GenTable genTable)
|
public void setTableFromOptions(GenTable genTable)
|
||||||
|
|
@ -471,7 +501,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);
|
||||||
|
|
@ -482,7 +512,7 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取代码生成地址
|
* 获取代码生成地址
|
||||||
*
|
*
|
||||||
* @param table 业务表信息
|
* @param table 业务表信息
|
||||||
* @param template 模板文件路径
|
* @param template 模板文件路径
|
||||||
* @return 生成地址
|
* @return 生成地址
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper">
|
<mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper">
|
||||||
|
|
||||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||||
<id property="columnId" column="column_id" />
|
<id property="columnId" column="column_id" />
|
||||||
<result property="tableId" column="table_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="updateBy" column="update_by" />
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectGenTableColumnVo">
|
<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
|
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>
|
</sql>
|
||||||
|
|
||||||
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
|
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
|
||||||
<include refid="selectGenTableColumnVo"/>
|
<include refid="selectGenTableColumnVo"/>
|
||||||
where table_id = #{tableId}
|
where table_id = #{tableId}
|
||||||
order by sort
|
order by sort
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
<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
|
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})
|
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
||||||
order by ordinal_position
|
order by ordinal_position
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
|
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
|
||||||
insert into gen_table_column (
|
insert into gen_table_column (
|
||||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||||
|
|
@ -88,40 +88,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
||||||
update gen_table_column
|
update gen_table_column
|
||||||
<set>
|
<set>
|
||||||
column_comment = #{columnComment},
|
<if test="columnComment != null and columnComment != ''">column_comment = #{columnComment},</if>
|
||||||
java_type = #{javaType},
|
<if test="columnType != null and columnType != ''">column_type = #{columnType},</if>
|
||||||
java_field = #{javaField},
|
<if test="javaType != null and javaType != ''">java_type = #{javaType},</if>
|
||||||
is_insert = #{isInsert},
|
<if test="javaField != null and javaField != ''">java_field = #{javaField},</if>
|
||||||
is_edit = #{isEdit},
|
<if test="isInsert != ''">is_insert = #{isInsert},</if>
|
||||||
is_list = #{isList},
|
<if test="isEdit != ''">is_edit = #{isEdit},</if>
|
||||||
is_query = #{isQuery},
|
<if test="isList != ''">is_list = #{isList},</if>
|
||||||
is_required = #{isRequired},
|
<if test="isQuery != ''">is_query = #{isQuery},</if>
|
||||||
query_type = #{queryType},
|
<if test="isRequired != null and isRequired != ''"> is_required = #{isRequired},</if>
|
||||||
html_type = #{htmlType},
|
<if test="queryType != null and queryType != ''"> query_type = #{queryType},</if>
|
||||||
dict_type = #{dictType},
|
<if test="htmlType != null and htmlType != ''"> html_type = #{htmlType},</if>
|
||||||
sort = #{sort},
|
<if test="dictType != null and dictType != ''"> dict_type = #{dictType},</if>
|
||||||
update_by = #{updateBy},
|
<if test="sort != null and sort != ''"> sort = #{sort},</if>
|
||||||
|
<if test="updateBy != null and updateBy != ''"> update_by = #{updateBy},</if>
|
||||||
update_time = sysdate()
|
update_time = sysdate()
|
||||||
</set>
|
</set>
|
||||||
where column_id = #{columnId}
|
where column_id = #{columnId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteGenTableColumnByIds" parameterType="Long">
|
<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=")">
|
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||||
#{tableId}
|
#{tableId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="deleteGenTableColumns">
|
<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=")">
|
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||||
#{item.columnId}
|
#{item.columnId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue