update 代码生成sql模板适配雪花id
parent
e2417b433a
commit
eaf6fdc445
|
|
@ -11,7 +11,6 @@ import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
import com.ruoyi.gen.domain.GenTable;
|
import com.ruoyi.gen.domain.GenTable;
|
||||||
import com.ruoyi.gen.domain.GenTableColumn;
|
import com.ruoyi.gen.domain.GenTableColumn;
|
||||||
import com.ruoyi.gen.service.IGenTableColumnService;
|
|
||||||
import com.ruoyi.gen.service.IGenTableService;
|
import com.ruoyi.gen.service.IGenTableService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
@ -38,7 +37,6 @@ import java.util.Map;
|
||||||
public class GenController extends BaseController {
|
public class GenController extends BaseController {
|
||||||
|
|
||||||
private final IGenTableService genTableService;
|
private final IGenTableService genTableService;
|
||||||
private final IGenTableColumnService genTableColumnService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询代码生成列表
|
* 查询代码生成列表
|
||||||
|
|
@ -59,7 +57,7 @@ public class GenController extends BaseController {
|
||||||
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
|
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
|
||||||
GenTable table = genTableService.selectGenTableById(tableId);
|
GenTable table = genTableService.selectGenTableById(tableId);
|
||||||
List<GenTable> tables = genTableService.selectGenTableAll();
|
List<GenTable> tables = genTableService.selectGenTableAll();
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("info", table);
|
map.put("info", table);
|
||||||
map.put("rows", list);
|
map.put("rows", list);
|
||||||
|
|
@ -84,7 +82,7 @@ public class GenController extends BaseController {
|
||||||
@GetMapping(value = "/column/{tableId}")
|
@GetMapping(value = "/column/{tableId}")
|
||||||
public TableDataInfo<GenTableColumn> columnList(Long tableId) {
|
public TableDataInfo<GenTableColumn> columnList(Long tableId) {
|
||||||
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
|
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
||||||
dataInfo.setRows(list);
|
dataInfo.setRows(list);
|
||||||
dataInfo.setTotal(list.size());
|
dataInfo.setTotal(list.size());
|
||||||
return dataInfo;
|
return dataInfo;
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,12 @@ public class GenTable extends BaseEntity {
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String treeName;
|
private String treeName;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 菜单id列表
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Long> menuIds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上级菜单ID字段
|
* 上级菜单ID字段
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
package com.ruoyi.gen.service;
|
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.ruoyi.gen.domain.GenTableColumn;
|
|
||||||
import com.ruoyi.gen.mapper.GenTableColumnMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务字段 服务层实现
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Service
|
|
||||||
public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
|
||||||
|
|
||||||
private final GenTableColumnMapper baseMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务字段列表
|
|
||||||
*
|
|
||||||
* @param tableId 业务字段编号
|
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
|
||||||
return baseMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
|
||||||
.eq(GenTableColumn::getTableId, tableId)
|
|
||||||
.orderByAsc(GenTableColumn::getSort));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增业务字段
|
|
||||||
*
|
|
||||||
* @param genTableColumn 业务字段信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
|
||||||
return baseMapper.insert(genTableColumn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改业务字段
|
|
||||||
*
|
|
||||||
* @param genTableColumn 业务字段信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int updateGenTableColumn(GenTableColumn genTableColumn) {
|
|
||||||
return baseMapper.updateById(genTableColumn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除业务字段对象
|
|
||||||
*
|
|
||||||
* @param ids 需要删除的数据ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int deleteGenTableColumnByIds(String ids) {
|
|
||||||
return baseMapper.deleteBatchIds(Arrays.asList(Convert.toLongArray(ids)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.ruoyi.gen.service;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
|
import cn.hutool.core.lang.Snowflake;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
|
@ -31,7 +33,6 @@ import org.apache.velocity.Template;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import org.apache.velocity.app.Velocity;
|
import org.apache.velocity.app.Velocity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -57,6 +58,19 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
private final GenTableMapper baseMapper;
|
private final GenTableMapper baseMapper;
|
||||||
private final GenTableColumnMapper genTableColumnMapper;
|
private final GenTableColumnMapper genTableColumnMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询业务字段列表
|
||||||
|
*
|
||||||
|
* @param tableId 业务字段编号
|
||||||
|
* @return 业务字段集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||||
|
return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
||||||
|
.eq(GenTableColumn::getTableId, tableId)
|
||||||
|
.orderByAsc(GenTableColumn::getSort));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务信息
|
* 查询业务信息
|
||||||
*
|
*
|
||||||
|
|
@ -158,7 +172,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void updateGenTable(GenTable genTable) {
|
public void updateGenTable(GenTable genTable) {
|
||||||
String options = JsonUtils.toJsonString(genTable.getParams());
|
String options = JsonUtils.toJsonString(genTable.getParams());
|
||||||
genTable.setOptions(options);
|
genTable.setOptions(options);
|
||||||
|
|
@ -177,7 +190,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void deleteGenTableByIds(Long[] tableIds) {
|
public void deleteGenTableByIds(Long[] tableIds) {
|
||||||
List<Long> ids = Arrays.asList(tableIds);
|
List<Long> ids = Arrays.asList(tableIds);
|
||||||
baseMapper.deleteBatchIds(ids);
|
baseMapper.deleteBatchIds(ids);
|
||||||
|
|
@ -190,7 +202,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
* @param tableList 导入表列表
|
* @param tableList 导入表列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void importGenTable(List<GenTable> tableList) {
|
public void importGenTable(List<GenTable> tableList) {
|
||||||
String operName = LoginHelper.getUsername();
|
String operName = LoginHelper.getUsername();
|
||||||
try {
|
try {
|
||||||
|
|
@ -227,6 +238,12 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||||
|
Snowflake snowflake = IdUtil.getSnowflake();
|
||||||
|
List<Long> menuIds = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
menuIds.add(snowflake.nextId());
|
||||||
|
}
|
||||||
|
table.setMenuIds(menuIds);
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
|
|
@ -271,6 +288,12 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
public void generatorCode(String tableName) {
|
public void generatorCode(String tableName) {
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||||
|
Snowflake snowflake = IdUtil.getSnowflake();
|
||||||
|
List<Long> menuIds = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
menuIds.add(snowflake.nextId());
|
||||||
|
}
|
||||||
|
table.setMenuIds(menuIds);
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
// 设置主键列信息
|
// 设置主键列信息
|
||||||
|
|
@ -304,7 +327,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void synchDb(String tableName) {
|
public void synchDb(String tableName) {
|
||||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||||
List<GenTableColumn> tableColumns = table.getColumns();
|
List<GenTableColumn> tableColumns = table.getColumns();
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
package com.ruoyi.gen.service;
|
|
||||||
|
|
||||||
import com.ruoyi.gen.domain.GenTableColumn;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务字段 服务层
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public interface IGenTableColumnService {
|
|
||||||
/**
|
|
||||||
* 查询业务字段列表
|
|
||||||
*
|
|
||||||
* @param tableId 业务字段编号
|
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
|
||||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增业务字段
|
|
||||||
*
|
|
||||||
* @param genTableColumn 业务字段信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
int insertGenTableColumn(GenTableColumn genTableColumn);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改业务字段
|
|
||||||
*
|
|
||||||
* @param genTableColumn 业务字段信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
int updateGenTableColumn(GenTableColumn genTableColumn);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除业务字段信息
|
|
||||||
*
|
|
||||||
* @param ids 需要删除的数据ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
int deleteGenTableColumnByIds(String ids);
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.gen.service;
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
import com.ruoyi.gen.domain.GenTable;
|
import com.ruoyi.gen.domain.GenTable;
|
||||||
|
import com.ruoyi.gen.domain.GenTableColumn;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -14,6 +15,14 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public interface IGenTableService {
|
public interface IGenTableService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询业务字段列表
|
||||||
|
*
|
||||||
|
* @param tableId 业务字段编号
|
||||||
|
* @return 业务字段集合
|
||||||
|
*/
|
||||||
|
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||||
|
|
||||||
TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
|
TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
|
||||||
|
|
||||||
TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);
|
TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,19 @@
|
||||||
-- 菜单 SQL
|
-- 菜单 SQL
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
|
values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
|
||||||
|
|
||||||
-- 按钮父菜单ID
|
-- 按钮 SQL
|
||||||
SELECT @parentId := LAST_INSERT_ID();
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, '');
|
||||||
-- 按钮 SQL
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, '');
|
values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, '');
|
values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, '');
|
values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, '');
|
values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
|
||||||
values('${functionName}导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, '');
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue