修缮细节,后几天准备处理模板
This commit is contained in:
parent
292b10e6ee
commit
7f89288b19
@ -84,7 +84,7 @@ public class GenController extends BaseController {
|
||||
GenJoinTable genJoinTable = new GenJoinTable();
|
||||
genJoinTable.setTableId(tableId);
|
||||
List<GenJoinTable> selectGenJoinTableList = genJoinTableService.selectGenJoinTableList(genJoinTable);
|
||||
genTableVo.setJoins(selectGenJoinTableList);
|
||||
genTableVo.setJoinTablesMate(selectGenJoinTableList);
|
||||
Map<Long, GenTable> joinTableMap = new HashMap<Long, GenTable>();
|
||||
joinTableMap.put(tableId, table);
|
||||
selectGenJoinTableList.forEach(i -> {
|
||||
@ -179,7 +179,7 @@ public class GenController extends BaseController {
|
||||
genTableService.validateEdit(genTable);
|
||||
genTableService.updateGenTable(genTable);
|
||||
genJoinTableService.deleteGenJoinTableByTableId(genTable.getTableId());
|
||||
genTableVo.getJoins().forEach(i -> {
|
||||
genTableVo.getJoinTablesMate().forEach(i -> {
|
||||
genJoinTableService.insertGenJoinTable(i);
|
||||
});
|
||||
return success();
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.ruoyi.generator.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import lombok.Data;
|
||||
@ -17,6 +19,9 @@ public class GenJoinTable extends BaseEntity {
|
||||
/** 关联表编号 */
|
||||
private Long rightTableId;
|
||||
|
||||
/** 新引入的表 */
|
||||
private Long newTableId;
|
||||
|
||||
/** 主表别名 */
|
||||
private String leftTableAlias;
|
||||
|
||||
@ -32,4 +37,9 @@ public class GenJoinTable extends BaseEntity {
|
||||
/** 连接类型 */
|
||||
private String joinType;
|
||||
|
||||
/** 关联字段 */
|
||||
private List<String> joinColumns;
|
||||
|
||||
private Long orderNum;
|
||||
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.ruoyi.generator.domain;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GenJoinTableColumn extends BaseEntity {
|
||||
|
||||
/** 归属表编号 */
|
||||
private Long tableId;
|
||||
|
||||
/** 关联表编号 */
|
||||
private Long rightTableId;
|
||||
|
||||
/** 编号 */
|
||||
private Long columnId;
|
||||
|
||||
/** 关联表别名 */
|
||||
private String rightTableAlias;
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ public class GenTableVo extends BaseEntity {
|
||||
|
||||
private List<GenTableColumn> columns;
|
||||
|
||||
private List<GenJoinTable> joins;
|
||||
private List<GenJoinTable> joinTablesMate;
|
||||
|
||||
@Valid
|
||||
private Collection<GenTable> joinTables;
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.generator.handler;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
public class ListStringTypeHandler extends BaseTypeHandler<List<String>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
String value = StringUtils.join(parameter, ",");
|
||||
ps.setString(i, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String value = rs.getString(columnName);
|
||||
return StringUtils.isBlank(value) ? null : StringUtils.str2List(value, ",", true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String value = rs.getString(columnIndex);
|
||||
return StringUtils.isBlank(value) ? null : StringUtils.str2List(value, ",", true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String value = cs.getString(columnIndex);
|
||||
return StringUtils.isBlank(value) ? null : StringUtils.str2List(value, ",", true, true);
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,23 @@
|
||||
package com.ruoyi.generator.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.constant.GenConstants;
|
||||
import com.ruoyi.generator.domain.GenJoinTable;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.vo.GenTableVo;
|
||||
import com.ruoyi.generator.mapper.GenJoinTableMapper;
|
||||
import com.ruoyi.generator.mapper.GenTableMapper;
|
||||
|
||||
/**
|
||||
* 代码生成关联字段Service业务层处理
|
||||
@ -20,6 +30,9 @@ public class GenJoinTableServiceImpl implements IGenJoinTableService {
|
||||
@Autowired
|
||||
private GenJoinTableMapper genJoinTableMapper;
|
||||
|
||||
@Autowired
|
||||
private GenTableMapper genTableMapper;
|
||||
|
||||
/**
|
||||
* 查询代码生成关联字段列表
|
||||
*
|
||||
@ -31,6 +44,57 @@ public class GenJoinTableServiceImpl implements IGenJoinTableService {
|
||||
return genJoinTableMapper.selectGenJoinTableList(genJoinTable);
|
||||
}
|
||||
|
||||
public GenTable selectGenTableById(Long id) {
|
||||
GenTable genTable = genTableMapper.selectGenTableById(id);
|
||||
setTableFromOptions(genTable);
|
||||
return genTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置代码生成其他选项值
|
||||
*
|
||||
* @param genTable 设置后的生成对象
|
||||
*/
|
||||
public void setTableFromOptions(GenTable genTable) {
|
||||
JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
|
||||
if (StringUtils.isNotNull(paramsObj)) {
|
||||
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
|
||||
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
|
||||
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);
|
||||
genTable.setParentMenuId(parentMenuId);
|
||||
genTable.setParentMenuName(parentMenuName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenTableVo selectGenJoinTableVoListByGenTable(GenTable table) {
|
||||
GenTableVo genTableVo = new GenTableVo();
|
||||
genTableVo.setTable(table);
|
||||
genTableVo.setColumns(table.getColumns());
|
||||
GenJoinTable genJoinTable = new GenJoinTable();
|
||||
genJoinTable.setTableId(table.getTableId());
|
||||
List<GenJoinTable> selectGenJoinTableList = this.selectGenJoinTableList(genJoinTable);
|
||||
genTableVo.setJoinTablesMate(selectGenJoinTableList);
|
||||
Map<Long, GenTable> joinTableMap = new HashMap<Long, GenTable>();
|
||||
joinTableMap.put(table.getTableId(), table);
|
||||
selectGenJoinTableList.forEach(i -> {
|
||||
if (Objects.isNull(joinTableMap.get(i.getLeftTableId()))) {
|
||||
joinTableMap.put(i.getLeftTableId(), this.selectGenTableById(i.getLeftTableId()));
|
||||
}
|
||||
if (Objects.isNull(joinTableMap.get(i.getRightTableId()))) {
|
||||
joinTableMap.put(i.getRightTableId(), this.selectGenTableById(i.getRightTableId()));
|
||||
}
|
||||
});
|
||||
genTableVo.setJoinTables(joinTableMap.values());
|
||||
return genTableVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增代码生成关联字段
|
||||
*
|
||||
|
@ -32,6 +32,7 @@ import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.constant.GenConstants;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import com.ruoyi.generator.domain.vo.GenTableVo;
|
||||
import com.ruoyi.generator.mapper.GenTableColumnMapper;
|
||||
import com.ruoyi.generator.mapper.GenTableMapper;
|
||||
import com.ruoyi.generator.util.GenUtils;
|
||||
@ -53,6 +54,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
@Autowired
|
||||
private GenTableColumnMapper genTableColumnMapper;
|
||||
|
||||
@Autowired
|
||||
private IGenJoinTableService genJoinTableService;
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
@ -195,8 +199,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
// 设置主键列信息
|
||||
setPkColumn(table);
|
||||
VelocityInitializer.initVelocity();
|
||||
GenTableVo genTableVo = genJoinTableService.selectGenJoinTableVoListByGenTable(table);
|
||||
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
VelocityContext context = VelocityUtils.prepareContext(genTableVo);
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
|
||||
@ -240,8 +245,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
setPkColumn(table);
|
||||
|
||||
VelocityInitializer.initVelocity();
|
||||
GenTableVo genTableVo = genJoinTableService.selectGenJoinTableVoListByGenTable(table);
|
||||
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
VelocityContext context = VelocityUtils.prepareContext(genTableVo);
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
|
||||
@ -338,8 +344,8 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
setPkColumn(table);
|
||||
|
||||
VelocityInitializer.initVelocity();
|
||||
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
GenTableVo genTableVo = genJoinTableService.selectGenJoinTableVoListByGenTable(table);
|
||||
VelocityContext context = VelocityUtils.prepareContext(genTableVo);
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
|
||||
|
@ -3,6 +3,8 @@ package com.ruoyi.generator.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.generator.domain.GenJoinTable;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.vo.GenTableVo;
|
||||
|
||||
/**
|
||||
* 代码生成关联字段Service接口
|
||||
@ -39,4 +41,6 @@ public interface IGenJoinTableService {
|
||||
* 根据tableId删除字段关联
|
||||
*/
|
||||
public int deleteGenJoinTableByTableId(Long tableId);
|
||||
|
||||
public GenTableVo selectGenJoinTableVoListByGenTable(GenTable table);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.constant.GenConstants;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import com.ruoyi.generator.domain.vo.GenTableVo;
|
||||
|
||||
/**
|
||||
* 模板处理工具类
|
||||
@ -36,8 +37,9 @@ public class VelocityUtils
|
||||
*
|
||||
* @return 模板列表
|
||||
*/
|
||||
public static VelocityContext prepareContext(GenTable genTable)
|
||||
public static VelocityContext prepareContext(GenTableVo genTableVo)
|
||||
{
|
||||
GenTable genTable = genTableVo.getTable();
|
||||
String moduleName = genTable.getModuleName();
|
||||
String businessName = genTable.getBusinessName();
|
||||
String packageName = genTable.getPackageName();
|
||||
|
@ -13,14 +13,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="leftTableFk" column="left_table_fk" />
|
||||
<result property="rightTableFk" column="right_table_fk" />
|
||||
<result property="joinType" column="join_type" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="orderNum" column="order_num"/>
|
||||
<result property="newTableId" column="new_table_id"/>
|
||||
<result property="joinColumns" column="join_columns" typeHandler="com.ruoyi.generator.handler.ListStringTypeHandler"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenJoinTableVo">
|
||||
select table_id, left_table_id, right_table_id, left_table_alias, right_table_alias, left_table_fk,right_table_fk, join_type, create_by, create_time, update_by, update_time from gen_join_table
|
||||
select table_id, left_table_id, right_table_id, left_table_alias, right_table_alias, left_table_fk, right_table_fk, join_type, join_columns, order_num, new_table_id from gen_join_table
|
||||
</sql>
|
||||
|
||||
<select id="selectGenJoinTableList" parameterType="GenJoinTable" resultMap="GenJoinTableResult">
|
||||
@ -34,7 +33,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="leftTableAlias != null and leftTableAlias != ''"> and left_table_alias = #{leftTableAlias}</if>
|
||||
<if test="rightTableAlias != null and rightTableAlias != ''"> and right_table_alias = #{rightTableAlias}</if>
|
||||
<if test="joinType != null and joinType != ''"> and join_type = #{joinType}</if>
|
||||
<if test="orderNum != null"> and order_num = #{orderNum}</if>
|
||||
<if test="newTableId != null"> and new_table_id = #{newTableId}</if>
|
||||
</where>
|
||||
order by order_num asc
|
||||
</select>
|
||||
|
||||
<insert id="insertGenJoinTable" parameterType="GenJoinTable">
|
||||
@ -48,10 +50,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="leftTableFk != null"> left_table_fk,</if>
|
||||
<if test="rightTableFk != null"> right_table_fk,</if>
|
||||
<if test="joinType != null">join_type,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="joinColumns != null">join_columns,</if>
|
||||
<if test="orderNum != null">order_num,</if>
|
||||
<if test="newTableId != null">new_table_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="tableId != null">#{tableId},</if>
|
||||
@ -62,10 +63,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="leftTableFk != null">#{leftTableFk},</if>
|
||||
<if test="rightTableFk != null">#{rightTableFk},</if>
|
||||
<if test="joinType != null">#{joinType},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="joinColumns != null">#{joinColumns,typeHandler=com.ruoyi.generator.handler.ListStringTypeHandler},</if>
|
||||
<if test="orderNum != null">#{orderNum},</if>
|
||||
<if test="newTableId != null">#{newTableId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@ -79,16 +79,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="leftTableFk != null"> left_table_fk = #{leftTableFk},</if>
|
||||
<if test="rightTableFk != null"> right_table_fk = #{rightTableFk},</if>
|
||||
<if test="joinType != null">join_type = #{joinType},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="joinColumns != null">join_columns = #{joinColumns,typeHandler=com.ruoyi.generator.handler.ListStringTypeHandler},</if>
|
||||
<if test="orderNum != null">order_num = #{orderNum},</if>
|
||||
<if test="newTableId != null">new_table_id = #{newTableId},</if>
|
||||
</trim>
|
||||
where gen_join_table.table_id = #{tableId} and gen_join_table.right_table_id = #{rightTableId}
|
||||
</update>
|
||||
|
||||
<!-- deleteGenJoinTableByTableId -->
|
||||
|
||||
<delete id="deleteGenJoinTableByTableId">
|
||||
delete from gen_join_table where table_id = #{tableId}
|
||||
</delete>
|
||||
|
@ -78,12 +78,11 @@ CREATE TABLE `gen_join_table` (
|
||||
`left_table_fk` varchar(200) NOT NULL COMMENT '主表别名',
|
||||
`right_table_fk` varchar(200) NOT NULL COMMENT '关联表别名',
|
||||
`join_type` varchar(200) NOT NULL COMMENT '关联类型',
|
||||
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
`join_columns` varchar(500) NOT NULL COMMENT '关联字段',
|
||||
`order_num` varchar(64) NOT NULL COMMENT '序号',
|
||||
`new_table_id` bigint NOT NULL COMMENT '新表编号',
|
||||
PRIMARY KEY (`table_id`,`right_table_id`,`left_table_id`)
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '代码生成关联表字段';
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '代码生成关联表';
|
||||
|
||||
|
||||
insert into sys_menu values('116', '代码生成', '3', '2', 'gen', 'tool/gen/index', '', '', 1, 0, 'C', '0', '0', 'tool:gen:list', 'code', 'admin', sysdate(), '', null, '代码生成菜单');
|
||||
|
Loading…
Reference in New Issue
Block a user